From 3250c41965b37d600582032b06a79e4f277f558c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 04:04:22 +0000 Subject: [PATCH 001/140] Auto-generated commit a5de702123c0f230fcae6f9135c97b5b63c4eed4 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 350 +++++++ index.d.ts | 180 ++++ index.mjs | 4 + index.mjs.map | 1 + package.json | 38 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 3772 insertions(+) create mode 100644 CONTRIBUTORS create mode 100644 LICENSE create mode 100644 NOTICE create mode 100644 README.md create mode 100644 index.d.ts create mode 100644 index.mjs create mode 100644 index.mjs.map create mode 100644 package.json create mode 100644 stats.html diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..e5c896d --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,28 @@ +# This file is generated by tools/scripts/update_contributors. +# +# Contributors listed in alphabetical order. + +Ali Salesi +Athan Reines +Brendan Graetz +Bruno Fenzl +Christopher Dambamuromo +Dominik Moritz +Frank Kovacs +James +Jithin KS +Joey Reed +Joris Labie +Justin Dennison +Marcus +Matt Cochrane +Milan Raj +Momtchil Momtchev +Ognjen Jevremović +Philipp Burckhardt +Ricky Reusser +Ryan Seal +Seyyed Parsa Neshaei +Shraddheya Shendre +dorrin-sot <59933477+dorrin-sot@users.noreply.github.com> +rei2hu diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fcc9934 --- /dev/null +++ b/LICENSE @@ -0,0 +1,481 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by this +license (the "Software") to use, reproduce, display, distribute, execute, and +transmit the Software, and to prepare derivative works of the Software, and to +permit third-parties to whom the Software is furnished to do so, all subject to +the following: + +The copyright notices in the Software and this entire statement, including the +above license grant, this restriction and the following disclaimer, must be +included in all copies of the Software, in whole or in part, and all derivative +works of the Software, unless such copies or derivative works are solely in the +form of machine-executable object code generated by a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES +OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + + + +DEPENDENCIES + +The library links against the following external libraries, which have their own +licenses: + +* OpenBLAS + +Copyright (c) 2011-2014, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +* Electron + +Copyright (c) 2013-2017 GitHub Inc. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +* Boost + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + + +* Cephes + +Copyright (c) 1984-2000 Stephen L. Moshier + +Some software in this archive may be from the book _Methods and Programs for +Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) +or from the Cephes Mathematical Library, a commercial product. In either event, +it is copyrighted by the author. What you see here may be used freely but it +comes with no support or guarantee. + +Stephen L. Moshier +moshier@na-net.ornl.gov + + + +ATTRIBUTION + +The library contains implementations from the following external libraries, +which have their own licenses: + +* FreeBSD + +Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + +* FDLIBM + +Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + +* Go + +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +* SLATEC Common Mathematical Library + +Public domain. + + +* ESLint + +Copyright JS Foundation and other contributors, https://js.foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + +* StatsFuns.jl + +Copyright (c) 2015: Dahua Lin. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +* SpecialFunctions.jl + +The MIT License (MIT) + +Copyright (c) 2017 Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and others: + +https://github.com/JuliaMath/SpecialFunctions.jl/graphs/contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +* MT19937 + +Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..10e6ba1 --- /dev/null +++ b/NOTICE @@ -0,0 +1 @@ +Copyright (c) 2016-2022 The Stdlib Authors. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a94b841 --- /dev/null +++ b/README.md @@ -0,0 +1,350 @@ + + +# Deep Set + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Set a nested property value. + + + +
+ +## Usage + +```javascript +import deepSet from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@esm/index.mjs'; +``` + +#### deepSet( obj, path, value\[, options] ) + +Sets a nested property value. + + + +```javascript +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = deepSet( obj, 'a.b.c', 'beep' ); +// returns true + +console.log( obj ); +// => { 'a': { 'b': { 'c': 'beep' } } } +``` + +If the function is able to deep set a nested property, the function returns `true`; otherwise, the function returns `false`. + + + +```javascript +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = deepSet( obj, 'a.b.c', 'woot' ); +// returns true + +bool = deepSet( obj, 'a.beep.c', 'boop' ); +// returns false + +bool = deepSet( null, 'a.beep.c', 'boop' ); +// returns false + +bool = deepSet( 'bap', 'a.beep.c', 'boop' ); +// returns false +``` + +For `paths` including `arrays`, specify the numeric index. + + + +```javascript +var arr = [ + { 'a': [ { 'x': 5 } ] }, + { 'a': [ { 'x': 10 } ] } +]; + +var bool = deepSet( arr, '1.a.0.x', 25 ); +// returns true + +console.log( arr ); +/* => + [ + { 'a': [ { 'x': 5 } ] }, + { 'a': [ { 'x': 25 } ] } + ] +*/ +``` + +The key `path` may be specified as either a delimited `string` or a key `array`. + + + +```javascript +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = deepSet( obj, [ 'a', 'b', 'c' ], 'beep' ); // obj => { 'a': { 'b': { 'c': 'beep' } } } +// returns true +``` + +If `value` is a `function`, the argument is treated as a `callback` and should return a value to set. + + + +```javascript +function set( val ) { + var ch = val; + var i; + for ( i = 0; i < 4; i++ ) { + val += ch; + } + return val; +} +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = deepSet( obj, 'a.b.c', set ); // obj => { 'a': { 'b': { 'c': 'ddddd' } } } +// returns true +``` + +The function accepts the following `options`: + +- **sep**: key path separator. Default: `'.'`. +- **create**: `boolean` indicating whether to create a path if the key path does not already exist. Default: `false`. + +By default, the function assumes `dot` separated key values. To specify an alternative separator, set the `sep` option. + + + +```javascript +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = deepSet( obj, 'a/b/c', 'beep', { + 'sep': '/' +}); +// returns true + +console.log( obj ); +// => { 'a': { 'b': { 'c': 'beep' } } } +``` + +To create a key path which does not already exist, set the `create` option to `true`. + + + +```javascript +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = deepSet( obj, 'a.e.c', 'boop', { + 'create': true +}); +// returns true + +console.log( obj ); +/* => + { + 'a': { + 'b': { + 'c': 'beep' + }, + 'e': { + 'c': 'boop' + } + } + } +*/ +``` + +#### deepSet.factory( path\[, options] ) + +Creates a reusable deep set function. The factory method ensures a `deepSet` function is configured identically by using the same set of provided `options`. + +```javascript +var dset = deepSet.factory( 'a/b/c', { + 'create': true, + 'sep': '/' +}); +``` + +#### dset( obj, value ) + +Sets a nested property value. + + + +```javascript +var dset = deepSet.factory( 'a.b.c' ); + +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = dset( obj, 'beep' ); +// returns true + +console.log( obj ); +// => { 'a': { 'b': { 'c': 'beep' } } } +``` + +
+ + + +
+ +## Examples + + + +```html + + + + + + +``` + +
+ + + + + + + + + + + + +
+ +* * * + +## Notice + +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. + +For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. + +#### Community + +[![Chat][chat-image]][chat-url] + +--- + +## License + +See [LICENSE][stdlib-license]. + + +## Copyright + +Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. + +
+ + + + + + + + diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..1230c6e --- /dev/null +++ b/index.d.ts @@ -0,0 +1,180 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/** +* Interface defining function options. +*/ +interface Options { + /** + * Boolean indicating whether to create a path if the key path does not already exist. + */ + create?: boolean; + + /** + * Key path separator. + */ + sep?: string; +} + +/** +* Sets a nested property. +* +* @param obj - input object +* @param value - value to set +* @returns boolean indicating if the property was successfully set +*/ +type Unary = ( obj: any, value: any ) => boolean; + +/** +* Interface for setting nested property values. +*/ +interface DeepSet { + /** + * Sets a nested property value. + * + * @param obj - input object + * @param path - key path + * @param value - value to set + * @param options - function options + * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) + * @param options.sep - key path separator (default: '.') + * @returns boolean indicating if the property was successfully set + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var bool = deepSet( obj, 'a.b.c', 'woot' ); + * // returns true + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var bool = deepSet( obj, 'a.beep.c', 'boop' ); + * // returns false + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var bool = deepSet( null, 'a.beep.c', 'boop' ); + * // returns false + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); + * // returns false + * + * @example + * var arr = [ + * { 'a': [ {'x': 5} ] }, + * { 'a': [ {'x': 10} ] } + * ]; + * var bool = deepSet( arr, '1.a.0.x', 25 ); + * // returns true + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var bool = deepSet( obj, 'a/b/c', 'beep', { + * 'sep': '/' + * }); + * // returns true + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var bool = deepSet( obj, 'a.e.c', 'boop', { + * 'create': true + * }); + * // returns true + */ + ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length + + /** + * Creates a reusable deep set function. + * + * @param path - key path + * @param options - function options + * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) + * @param options.sep - key path separator (default: '.') + * @returns deep set function + * + * @example + * var dset = deepSet.factory( 'a/b/c', { + * 'create': true, + * 'sep': '/' + * }); + */ + factory( path: string | Array, options?: Options ): Unary; +} + +/** +* Sets a nested property value. +* +* @param obj - input object +* @param path - key path +* @param value - value to set +* @param options - function options +* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) +* @param options.sep - key path separator (default: '.') +* @returns boolean indicating if the property was successfully set +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( obj, 'a.b.c', 'woot' ); +* // returns true +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( obj, 'a.beep.c', 'boop' ); +* // returns false +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( null, 'a.beep.c', 'boop' ); +* // returns false +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); +* // returns false +* +* @example +* var arr = [ +* { 'a': [ {'x': 5} ] }, +* { 'a': [ {'x': 10} ] } +* ]; +* var bool = deepSet( arr, '1.a.0.x', 25 ); +* // returns true +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( obj, 'a/b/c', 'beep', { +* 'sep': '/' +* }); +* // returns true +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( obj, 'a.e.c', 'boop', { +* 'create': true +* }); +* // returns true +*/ +declare var deepSet: DeepSet; + + +// EXPORTS // + +export = deepSet; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f4ae696 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";var d=o.isPrimitive,l=r.isPrimitive,j=a,c=m,h=i;var u=function(e,t){return j(t)?c(t,"create")&&(e.create=t.create,!d(e.create))?new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","create",e.create)):c(t,"sep")&&(e.sep=t.sep,!l(e.sep))?new TypeError(h("invalid option. `%s` option must be a string. Option: `%s`.","sep",e.sep)):null:new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",t))},f={create:!1,sep:"."},v=t,b=m,g=p;var y=function(e,t,r,s){var i,n,o,a,m;for(n=t.length,i=!1,o=e,m=0;m3&&(a=P(o,s)))throw a;return n=i?t.split(o.sep):t,V(e,n,o.create,r)},q=r.isPrimitive,z=s,A=t,B=i,C=n,D=u,F=f,G=y;var H=function(e,t){var r,s,i,n;if(!(r=q(e))&&!z(e))throw new TypeError(B("invalid argument. Key path must be a string or a key array. Value: `%s`.",e));if(i=C(F),arguments.length>1&&(n=D(i,t)))throw n;return s=r?e.split(i.sep):e,o;function o(e,t){return!!A(e)&&G(e,s,i.create,t)}},I=K,J=H;e(I,"factory",J);var L=I;export{L as default,J as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..75fc6ae --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/deep_set.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar copy = require( '@stdlib/utils-copy' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.json' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar copy = require( '@stdlib/utils-copy' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.json' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar deepSet = require( './deep_set.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( deepSet, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n"],"names":["isBoolean","require$$0","isPrimitive","isString","require$$1","isObject","require$$2","hasOwnProp","require$$3","format","require$$4","validate_1","opts","options","create","TypeError","sep","isObjectLike","isFunction","dset","obj","props","val","bool","len","v","p","i","length","isArray","copy","validate","require$$5","defaults","require$$6","require$$7","deep_set","path","value","isStr","err","arguments","split","factory_1","deepSet","factory","lib"],"mappings":";;g3BAsBA,IAAIA,EAAYC,EAAuCC,YACnDC,EAAWC,EAAsCF,YACjDG,EAAWC,EACXC,EAAaC,EACbC,EAASC,EA+Cb,IAAAC,EAtBA,SAAmBC,EAAMC,GACxB,OAAMR,EAAUQ,GAGXN,EAAYM,EAAS,YACzBD,EAAKE,OAASD,EAAQC,QAChBd,EAAWY,EAAKE,SACd,IAAIC,UAAWN,EAAQ,+DAAgE,SAAUG,EAAKE,SAG1GP,EAAYM,EAAS,SACzBD,EAAKI,IAAMH,EAAQG,KACbb,EAAUS,EAAKI,MACb,IAAID,UAAWN,EAAQ,8DAA+D,MAAOG,EAAKI,MAGpG,KAdC,IAAID,UAAWN,EAAQ,qEAAsEI,2BC/BlGI,EAAehB,EACfM,EAAaH,EACbc,EAAaZ,EAuDjB,IAAAa,EAxCA,SAAkBC,EAAKC,EAAOP,EAAQQ,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNV,EAAcQ,IAFEE,IAAM,CAG1B,IAAMpB,EAAYkB,EAAGC,GAAM,CAC1B,IAAKZ,EAGJ,MAFAW,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTN,EAAYI,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,GCnDJN,EAAehB,EACfE,EAAWC,EAAsCF,YACjD2B,EAAUvB,EACVG,EAASD,EACTsB,EAAOpB,EACPqB,EAAWC,EACXC,EAAWC,EACXf,EAAOgB,EA2FX,IAAAC,EA9BA,SAAkBhB,EAAKiB,EAAMC,EAAOzB,GACnC,IAAI0B,EACAlB,EACAT,EACA4B,EACJ,IAAMvB,EAAcG,GACnB,OAAO,EAGR,KADAmB,EAAQpC,EAAUkC,MACFR,EAASQ,GACxB,MAAM,IAAItB,UAAWN,EAAQ,2EAA4E4B,IAG1G,GADAzB,EAAOkB,EAAMG,GACRQ,UAAUb,OAAS,IACvBY,EAAMT,EAAUnB,EAAMC,IAErB,MAAM2B,EAQR,OAJCnB,EADIkB,EACIF,EAAKK,MAAO9B,EAAKI,KAEjBqB,EAEFlB,EAAMC,EAAKC,EAAOT,EAAKE,OAAQwB,IC5FnCnC,EAAWF,EAAsCC,YACjD2B,EAAUzB,EACVa,EAAeX,EACfG,EAASD,EACTsB,EAAOpB,EACPqB,EAAWC,EACXC,EAAWC,EACXf,EAAOgB,EAsEX,IAAAQ,EA/CA,SAAkBN,EAAMxB,GACvB,IAAI0B,EACAlB,EACAT,EACA4B,EAGJ,KADAD,EAAQpC,EAAUkC,MACFR,EAASQ,GACxB,MAAM,IAAItB,UAAWN,EAAQ,2EAA4E4B,IAG1G,GADAzB,EAAOkB,EAAMG,GACRQ,UAAUb,OAAS,IACvBY,EAAMT,EAAUnB,EAAMC,IAErB,MAAM2B,EAQR,OAJCnB,EADIkB,EACIF,EAAKK,MAAO9B,EAAKI,KAEjBqB,EAEFO,EAcP,SAASA,EAASxB,EAAKkB,GACtB,QAAKrB,EAAcG,IACXD,EAAMC,EAAKC,EAAOT,EAAKE,OAAQwB,KC5CzCM,EAAAxC,EACAyC,EAAAvC,EAFAL,EAOA2C,EAAA,UAAAC,GAKA,IAAAC,EAAAF"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..933e45f --- /dev/null +++ b/package.json @@ -0,0 +1,38 @@ +{ + "name": "@stdlib/utils-deep-set", + "version": "0.0.0", + "description": "Set a nested property value.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/utils-deep-set.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "deep", + "set", + "assign", + "object", + "obj", + "array", + "nested", + "property", + "prop" + ], + "funding": { + "type": "patreon", + "url": "https://www.patreon.com/athan" + } +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..77fc876 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From c675fd35e9500baaf8797fbf5ac630c6f01d9c75 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Jun 2022 23:07:04 +0000 Subject: [PATCH 002/140] Transform error messages --- lib/deep_set.js | 4 ++-- lib/factory.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/deep_set.js b/lib/deep_set.js index 96e37f2..9a34262 100644 --- a/lib/deep_set.js +++ b/lib/deep_set.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -98,7 +98,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 3 ) { diff --git a/lib/factory.js b/lib/factory.js index a623517..0ff95f6 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -58,7 +58,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 1 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 7204d60..067c7f9 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.x", "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" }, From 1d8dd9603a14c5fb219d9ae95a69134daf8a8ea0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 07:27:13 +0000 Subject: [PATCH 003/140] Remove files --- index.d.ts | 180 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2874 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f4ae696..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";var d=o.isPrimitive,l=r.isPrimitive,j=a,c=m,h=i;var u=function(e,t){return j(t)?c(t,"create")&&(e.create=t.create,!d(e.create))?new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","create",e.create)):c(t,"sep")&&(e.sep=t.sep,!l(e.sep))?new TypeError(h("invalid option. `%s` option must be a string. Option: `%s`.","sep",e.sep)):null:new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",t))},f={create:!1,sep:"."},v=t,b=m,g=p;var y=function(e,t,r,s){var i,n,o,a,m;for(n=t.length,i=!1,o=e,m=0;m3&&(a=P(o,s)))throw a;return n=i?t.split(o.sep):t,V(e,n,o.create,r)},q=r.isPrimitive,z=s,A=t,B=i,C=n,D=u,F=f,G=y;var H=function(e,t){var r,s,i,n;if(!(r=q(e))&&!z(e))throw new TypeError(B("invalid argument. Key path must be a string or a key array. Value: `%s`.",e));if(i=C(F),arguments.length>1&&(n=D(i,t)))throw n;return s=r?e.split(i.sep):e,o;function o(e,t){return!!A(e)&&G(e,s,i.create,t)}},I=K,J=H;e(I,"factory",J);var L=I;export{L as default,J as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 75fc6ae..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/deep_set.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar copy = require( '@stdlib/utils-copy' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.json' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar copy = require( '@stdlib/utils-copy' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.json' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar deepSet = require( './deep_set.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( deepSet, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n"],"names":["isBoolean","require$$0","isPrimitive","isString","require$$1","isObject","require$$2","hasOwnProp","require$$3","format","require$$4","validate_1","opts","options","create","TypeError","sep","isObjectLike","isFunction","dset","obj","props","val","bool","len","v","p","i","length","isArray","copy","validate","require$$5","defaults","require$$6","require$$7","deep_set","path","value","isStr","err","arguments","split","factory_1","deepSet","factory","lib"],"mappings":";;g3BAsBA,IAAIA,EAAYC,EAAuCC,YACnDC,EAAWC,EAAsCF,YACjDG,EAAWC,EACXC,EAAaC,EACbC,EAASC,EA+Cb,IAAAC,EAtBA,SAAmBC,EAAMC,GACxB,OAAMR,EAAUQ,GAGXN,EAAYM,EAAS,YACzBD,EAAKE,OAASD,EAAQC,QAChBd,EAAWY,EAAKE,SACd,IAAIC,UAAWN,EAAQ,+DAAgE,SAAUG,EAAKE,SAG1GP,EAAYM,EAAS,SACzBD,EAAKI,IAAMH,EAAQG,KACbb,EAAUS,EAAKI,MACb,IAAID,UAAWN,EAAQ,8DAA+D,MAAOG,EAAKI,MAGpG,KAdC,IAAID,UAAWN,EAAQ,qEAAsEI,2BC/BlGI,EAAehB,EACfM,EAAaH,EACbc,EAAaZ,EAuDjB,IAAAa,EAxCA,SAAkBC,EAAKC,EAAOP,EAAQQ,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNV,EAAcQ,IAFEE,IAAM,CAG1B,IAAMpB,EAAYkB,EAAGC,GAAM,CAC1B,IAAKZ,EAGJ,MAFAW,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTN,EAAYI,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,GCnDJN,EAAehB,EACfE,EAAWC,EAAsCF,YACjD2B,EAAUvB,EACVG,EAASD,EACTsB,EAAOpB,EACPqB,EAAWC,EACXC,EAAWC,EACXf,EAAOgB,EA2FX,IAAAC,EA9BA,SAAkBhB,EAAKiB,EAAMC,EAAOzB,GACnC,IAAI0B,EACAlB,EACAT,EACA4B,EACJ,IAAMvB,EAAcG,GACnB,OAAO,EAGR,KADAmB,EAAQpC,EAAUkC,MACFR,EAASQ,GACxB,MAAM,IAAItB,UAAWN,EAAQ,2EAA4E4B,IAG1G,GADAzB,EAAOkB,EAAMG,GACRQ,UAAUb,OAAS,IACvBY,EAAMT,EAAUnB,EAAMC,IAErB,MAAM2B,EAQR,OAJCnB,EADIkB,EACIF,EAAKK,MAAO9B,EAAKI,KAEjBqB,EAEFlB,EAAMC,EAAKC,EAAOT,EAAKE,OAAQwB,IC5FnCnC,EAAWF,EAAsCC,YACjD2B,EAAUzB,EACVa,EAAeX,EACfG,EAASD,EACTsB,EAAOpB,EACPqB,EAAWC,EACXC,EAAWC,EACXf,EAAOgB,EAsEX,IAAAQ,EA/CA,SAAkBN,EAAMxB,GACvB,IAAI0B,EACAlB,EACAT,EACA4B,EAGJ,KADAD,EAAQpC,EAAUkC,MACFR,EAASQ,GACxB,MAAM,IAAItB,UAAWN,EAAQ,2EAA4E4B,IAG1G,GADAzB,EAAOkB,EAAMG,GACRQ,UAAUb,OAAS,IACvBY,EAAMT,EAAUnB,EAAMC,IAErB,MAAM2B,EAQR,OAJCnB,EADIkB,EACIF,EAAKK,MAAO9B,EAAKI,KAEjBqB,EAEFO,EAcP,SAASA,EAASxB,EAAKkB,GACtB,QAAKrB,EAAcG,IACXD,EAAMC,EAAKC,EAAOT,EAAKE,OAAQwB,KC5CzCM,EAAAxC,EACAyC,EAAAvC,EAFAL,EAOA2C,EAAA,UAAAC,GAKA,IAAAC,EAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 77fc876..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 62558bbb10c123c7a13026c24e2c6e1b1008757b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 07:27:57 +0000 Subject: [PATCH 004/140] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 45 +- benchmark/benchmark.js | 140 -- branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/deep_set.js | 121 - lib/defaults.json | 4 - lib/dset.js | 80 - lib/factory.js | 100 - lib/index.js | 58 - lib/validate.js | 74 - package.json | 61 +- stats.html | 2689 +++++++++++++++++++++ test/test.dset.js | 292 --- test/test.factory.js | 221 -- test/test.js | 201 -- test/test.validate.js | 131 - 44 files changed, 2718 insertions(+), 4675 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/deep_set.js delete mode 100644 lib/defaults.json delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index accdbff..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:07:04.430Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a10c773..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..334587c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e2e8f67 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/deep_set.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport deepSet from './deep_set.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( deepSet, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default deepSet;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly"],"mappings":";;u5BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,8BCdzC,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,ECiBR,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,GC9DvC,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,ICtCzCU,EAAAvB,EAAA,UAAAsB"} \ No newline at end of file diff --git a/lib/deep_set.js b/lib/deep_set.js deleted file mode 100644 index 9a34262..0000000 --- a/lib/deep_set.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 274affc..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "create": false, - "sep": "." -} diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 0ff95f6..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c63d66c..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var deepSet = require( './deep_set.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( deepSet, 'factory', factory ); - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 067c7f9..988c6f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-object-like": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a473846 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 2f3cef3..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From aba311acb21d3d205aead865bc2ebae1292ea3ff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 16:41:02 +0000 Subject: [PATCH 005/140] Transform error messages --- lib/deep_set.js | 4 ++-- lib/factory.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/deep_set.js b/lib/deep_set.js index 96e37f2..9a34262 100644 --- a/lib/deep_set.js +++ b/lib/deep_set.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -98,7 +98,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 3 ) { diff --git a/lib/factory.js b/lib/factory.js index a623517..0ff95f6 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -58,7 +58,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 1 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 7204d60..067c7f9 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.x", "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" }, From c91ed840baab4f466f5b3560076267984cc0b2ea Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 03:55:49 +0000 Subject: [PATCH 006/140] Remove files --- index.d.ts | 180 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2874 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 334587c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e2e8f67..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/deep_set.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport deepSet from './deep_set.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( deepSet, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default deepSet;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly"],"mappings":";;u5BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,8BCdzC,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,ECiBR,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,GC9DvC,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,ICtCzCU,EAAAvB,EAAA,UAAAsB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a473846..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 68882e24e190c48ffb66b442f018f831b8666c0e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 03:56:39 +0000 Subject: [PATCH 007/140] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 45 +- benchmark/benchmark.js | 140 -- branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/deep_set.js | 121 - lib/defaults.json | 4 - lib/dset.js | 80 - lib/factory.js | 100 - lib/index.js | 58 - lib/validate.js | 74 - package.json | 61 +- stats.html | 2689 +++++++++++++++++++++ test/test.dset.js | 292 --- test/test.factory.js | 221 -- test/test.js | 201 -- test/test.validate.js | 131 - 44 files changed, 2718 insertions(+), 4675 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/deep_set.js delete mode 100644 lib/defaults.json delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b557424..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:11:26.403Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a10c773..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..334587c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e2e8f67 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/deep_set.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport deepSet from './deep_set.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( deepSet, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default deepSet;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly"],"mappings":";;u5BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,8BCdzC,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,ECiBR,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,GC9DvC,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,ICtCzCU,EAAAvB,EAAA,UAAAsB"} \ No newline at end of file diff --git a/lib/deep_set.js b/lib/deep_set.js deleted file mode 100644 index 9a34262..0000000 --- a/lib/deep_set.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 274affc..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "create": false, - "sep": "." -} diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 0ff95f6..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c63d66c..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var deepSet = require( './deep_set.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( deepSet, 'factory', factory ); - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 067c7f9..988c6f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-object-like": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8a9bb53 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 2f3cef3..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 04f813119f91d7cb0b5d4861ac5ad86a8c370993 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 12:46:02 +0000 Subject: [PATCH 008/140] Transform error messages --- lib/deep_set.js | 4 ++-- lib/factory.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/deep_set.js b/lib/deep_set.js index 96e37f2..9a34262 100644 --- a/lib/deep_set.js +++ b/lib/deep_set.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -98,7 +98,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 3 ) { diff --git a/lib/factory.js b/lib/factory.js index a623517..0ff95f6 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -58,7 +58,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 1 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 7204d60..067c7f9 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.x", "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" }, From 856c6d57fa48db39f055162eca921a8c841b191a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 13:09:25 +0000 Subject: [PATCH 009/140] Remove files --- index.d.ts | 180 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2874 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 334587c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e2e8f67..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/deep_set.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport deepSet from './deep_set.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( deepSet, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default deepSet;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly"],"mappings":";;u5BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,8BCdzC,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,ECiBR,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,GC9DvC,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,ICtCzCU,EAAAvB,EAAA,UAAAsB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8a9bb53..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From f5b7d21ed17b734311f81a7e7396cae6db8609e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 13:10:11 +0000 Subject: [PATCH 010/140] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 687 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 45 +- benchmark/benchmark.js | 140 -- branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/deep_set.js | 121 - lib/defaults.json | 4 - lib/dset.js | 80 - lib/factory.js | 100 - lib/index.js | 58 - lib/validate.js | 74 - package.json | 61 +- stats.html | 2689 +++++++++++++++++++++ test/test.dset.js | 292 --- test/test.factory.js | 221 -- test/test.js | 201 -- test/test.validate.js | 131 - 43 files changed, 2718 insertions(+), 4640 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/deep_set.js delete mode 100644 lib/defaults.json delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 6726965..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,687 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a10c773..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..334587c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e2e8f67 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/deep_set.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport deepSet from './deep_set.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( deepSet, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default deepSet;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly"],"mappings":";;u5BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,8BCdzC,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,ECiBR,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,GC9DvC,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,ICtCzCU,EAAAvB,EAAA,UAAAsB"} \ No newline at end of file diff --git a/lib/deep_set.js b/lib/deep_set.js deleted file mode 100644 index 9a34262..0000000 --- a/lib/deep_set.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 274affc..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "create": false, - "sep": "." -} diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 0ff95f6..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c63d66c..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var deepSet = require( './deep_set.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( deepSet, 'factory', factory ); - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 067c7f9..988c6f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-object-like": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ae23c48 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 2f3cef3..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From e50fbc7a669fa4995443114be8226075af26f406 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:41:36 +0000 Subject: [PATCH 011/140] Transform error messages --- lib/deep_set.js | 4 ++-- lib/factory.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/deep_set.js b/lib/deep_set.js index 96e37f2..9a34262 100644 --- a/lib/deep_set.js +++ b/lib/deep_set.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -98,7 +98,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 3 ) { diff --git a/lib/factory.js b/lib/factory.js index a623517..0ff95f6 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -58,7 +58,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 1 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 7204d60..067c7f9 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.x", "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" }, From e6107c89f6061812b6887bd7a37c108babf5720e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 10:52:53 +0000 Subject: [PATCH 012/140] Remove files --- index.d.ts | 180 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2874 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 334587c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e2e8f67..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/deep_set.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport deepSet from './deep_set.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( deepSet, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default deepSet;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly"],"mappings":";;u5BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,8BCdzC,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,ECiBR,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,GC9DvC,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,ICtCzCU,EAAAvB,EAAA,UAAAsB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ae23c48..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From f6f20ea2d5710eba28d1c7cf5fa7122bc5541d3b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 10:53:42 +0000 Subject: [PATCH 013/140] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 45 +- benchmark/benchmark.js | 140 -- branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/deep_set.js | 121 - lib/defaults.json | 4 - lib/dset.js | 80 - lib/factory.js | 100 - lib/index.js | 58 - lib/validate.js | 74 - package.json | 61 +- stats.html | 2689 +++++++++++++++++++++ test/test.dset.js | 292 --- test/test.factory.js | 221 -- test/test.js | 201 -- test/test.validate.js | 131 - 44 files changed, 2718 insertions(+), 4714 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/deep_set.js delete mode 100644 lib/defaults.json delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index c4a33bb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:14:35.492Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a10c773..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..39cbea0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..3e4aa39 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/deep_set.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport deepSet from './deep_set.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( deepSet, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default deepSet;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,8BCdzC,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,ECiBR,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,GC9DvC,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,ICtCzCU,EAAAvB,EAAA,UAAAsB"} \ No newline at end of file diff --git a/lib/deep_set.js b/lib/deep_set.js deleted file mode 100644 index 9a34262..0000000 --- a/lib/deep_set.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 274affc..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "create": false, - "sep": "." -} diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 0ff95f6..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c63d66c..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var deepSet = require( './deep_set.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( deepSet, 'factory', factory ); - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 067c7f9..988c6f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-object-like": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..91282e7 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 2f3cef3..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From cc970969e47750239753f813bf51040250d1e94e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 04:22:55 +0000 Subject: [PATCH 014/140] Transform error messages --- lib/deep_set.js | 4 ++-- lib/factory.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/deep_set.js b/lib/deep_set.js index 96e37f2..9a34262 100644 --- a/lib/deep_set.js +++ b/lib/deep_set.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -98,7 +98,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 3 ) { diff --git a/lib/factory.js b/lib/factory.js index a623517..0ff95f6 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -58,7 +58,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 1 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 8214b3d..bf2f14e 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.x", "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" }, From e29e482da74b82aeaca998f90465ab4388b655b2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 18:39:43 +0000 Subject: [PATCH 015/140] Remove files --- index.d.ts | 180 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2874 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 39cbea0..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 3e4aa39..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/deep_set.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport deepSet from './deep_set.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( deepSet, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default deepSet;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,8BCdzC,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,ECiBR,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,GC9DvC,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,ICtCzCU,EAAAvB,EAAA,UAAAsB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 91282e7..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From c49405fea4c086d3906b379b0921648bc073b94d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 18:40:44 +0000 Subject: [PATCH 016/140] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 45 +- benchmark/benchmark.js | 140 -- branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/deep_set.js | 121 - lib/defaults.json | 4 - lib/dset.js | 80 - lib/factory.js | 100 - lib/index.js | 58 - lib/validate.js | 74 - package.json | 62 +- stats.html | 2689 +++++++++++++++++++++ test/test.dset.js | 292 --- test/test.factory.js | 221 -- test/test.js | 201 -- test/test.validate.js | 132 - 44 files changed, 2718 insertions(+), 4732 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/deep_set.js delete mode 100644 lib/defaults.json delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8025649..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:12:31.482Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a10c773..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..39cbea0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..3e4aa39 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/deep_set.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport deepSet from './deep_set.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( deepSet, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default deepSet;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,8BCdzC,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,ECiBR,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,GC9DvC,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,ICtCzCU,EAAAvB,EAAA,UAAAsB"} \ No newline at end of file diff --git a/lib/deep_set.js b/lib/deep_set.js deleted file mode 100644 index 9a34262..0000000 --- a/lib/deep_set.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 274affc..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "create": false, - "sep": "." -} diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 0ff95f6..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c63d66c..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var deepSet = require( './deep_set.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( deepSet, 'factory', factory ); - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index bf2f14e..988c6f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-object-like": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/boolean-ctor": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2f4a2e4 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0615992..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 505ada2ae163fb52a5583514c51c6f0a5191fa6a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 04:30:20 +0000 Subject: [PATCH 017/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a623517..0ff95f6 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -58,7 +58,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 96e37f2..9a34262 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -98,7 +98,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 8214b3d..bf2f14e 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.x", "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" }, From 545e8e0e995068da3e56bc1e31b25ae7a0aafb56 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Oct 2022 00:18:15 +0000 Subject: [PATCH 018/140] Remove files --- index.d.ts | 180 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2874 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 39cbea0..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 3e4aa39..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/deep_set.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport deepSet from './deep_set.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( deepSet, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default deepSet;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,8BCdzC,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,ECiBR,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,GC9DvC,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,ICtCzCU,EAAAvB,EAAA,UAAAsB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2f4a2e4..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From d1ea975251fe3b6580d354748b09a69dbf0bee29 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Oct 2022 00:18:57 +0000 Subject: [PATCH 019/140] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 45 +- benchmark/benchmark.js | 140 -- branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/dset.js | 80 - lib/factory.js | 100 - lib/index.js | 58 - lib/main.js | 121 - lib/validate.js | 74 - package.json | 62 +- stats.html | 2689 +++++++++++++++++++++ test/test.dset.js | 292 --- test/test.factory.js | 221 -- test/test.js | 201 -- test/test.validate.js | 132 - 44 files changed, 2718 insertions(+), 4732 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.json delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 368a270..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T01:37:29.069Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a10c773..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..39cbea0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e8f99d4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,8BCdzC,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,ECiBR,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,GC9DvC,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,ICtCzCU,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 274affc..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "create": false, - "sep": "." -} diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 0ff95f6..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9a34262..0000000 --- a/lib/main.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index bf2f14e..988c6f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-object-like": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/boolean-ctor": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f5b10bf --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0615992..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 7741a2831ba03414e081125684e0d131d413535e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 04:09:43 +0000 Subject: [PATCH 020/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a623517..0ff95f6 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -58,7 +58,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 96e37f2..9a34262 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -98,7 +98,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 8214b3d..bf2f14e 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.x", "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" }, From ec4be3b535bdc77148b2320bbeadd2b7f57bef95 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 15:24:09 +0000 Subject: [PATCH 021/140] Remove files --- index.d.ts | 180 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2874 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 39cbea0..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e8f99d4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,8BCdzC,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,GAKNC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,GAMV,OAAOH,ECiBR,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,GC9DvC,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,ICtCzCU,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f5b10bf..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 0ef9f9c539e2b43191a20ee51b159ead61905720 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 15:25:02 +0000 Subject: [PATCH 022/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/dset.js | 80 - lib/factory.js | 100 - lib/index.js | 58 - lib/main.js | 121 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4044 +++++++++++++++++++++ test/test.dset.js | 292 -- test/test.factory.js | 221 -- test/test.js | 201 - test/test.validate.js | 132 - 44 files changed, 4073 insertions(+), 4732 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.json delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1dfacef..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:25:39.856Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 667222f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9113bfe..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a10c773..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..39cbea0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..b87b3c7 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,2BC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCgBA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CC/DA,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CC1CAU,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 274affc..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "create": false, - "sep": "." -} diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 0ff95f6..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9a34262..0000000 --- a/lib/main.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index bf2f14e..988c6f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-object-like": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/boolean-ctor": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e6928a3 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0615992..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 5c5e7c7c20205a6606a4e1ca1c78c4879e705f5e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 3 Nov 2022 22:03:23 +0000 Subject: [PATCH 023/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a623517..0ff95f6 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -58,7 +58,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 96e37f2..9a34262 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -98,7 +98,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 8214b3d..bf2f14e 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.x", "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" }, From 57f14781487e3f534ddb47923480d16f0771d83b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 07:49:06 +0000 Subject: [PATCH 024/140] Remove files --- index.d.ts | 180 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4229 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 39cbea0..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index b87b3c7..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,2BC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCgBA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CC/DA,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CC1CAU,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e6928a3..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 7c5037fbe1e3cfd840df68c6d030ab3d997927a8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 07:50:14 +0000 Subject: [PATCH 025/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/dset.js | 80 - lib/factory.js | 100 - lib/index.js | 58 - lib/main.js | 121 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4044 +++++++++++++++++++++ test/test.dset.js | 292 -- test/test.factory.js | 221 -- test/test.js | 201 - test/test.validate.js | 132 - 44 files changed, 4073 insertions(+), 4753 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.json delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f021b4c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T22:02:52.800Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 667222f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a10c773..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..39cbea0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..b87b3c7 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,2BC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCgBA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CC/DA,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CC1CAU,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 274affc..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "create": false, - "sep": "." -} diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 0ff95f6..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9a34262..0000000 --- a/lib/main.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index bf2f14e..988c6f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-object-like": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/boolean-ctor": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..699e0b3 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0615992..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 7cd8bf3c29eb1c550c3be5069b98d6a144693795 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 04:04:13 +0000 Subject: [PATCH 026/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a623517..0ff95f6 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -58,7 +58,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 96e37f2..9a34262 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -98,7 +98,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 4e10147..015f56b 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.x", "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" }, From d4e079d88852256e5a4c590eddcd3cc0174bc6cd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 14:38:36 +0000 Subject: [PATCH 027/140] Remove files --- index.d.ts | 180 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4229 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 39cbea0..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index b87b3c7..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport isObjectLike from '@stdlib/assert-is-object-like' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport copy from '@stdlib/utils-copy' ;\nimport validate from './validate.js' ;\nimport defaults from './defaults.json' ;\nimport dset from './dset.js' ;\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set' ;\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,2BC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCgBA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CC/DA,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CC1CAU,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 699e0b3..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 55ce349d3e5230c3005d5be072b59b8a06665ff3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 14:39:22 +0000 Subject: [PATCH 028/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 183 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/dset.js | 80 - lib/factory.js | 100 - lib/index.js | 58 - lib/main.js | 121 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4044 +++++++++++++++++++++ test/test.dset.js | 292 -- test/test.factory.js | 221 -- test/test.js | 201 - test/test.validate.js | 132 - 44 files changed, 4073 insertions(+), 4758 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.json delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index c5bd979..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T01:52:28.046Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 667222f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a10c773..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..39cbea0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..94010c4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport copy from '@stdlib/utils-copy';\nimport validate from './validate.js';\nimport defaults from './defaults.json';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport copy from '@stdlib/utils-copy';\nimport validate from './validate.js';\nimport defaults from './defaults.json';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,2BC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCgBA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CC/DA,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CC1CAU,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 274affc..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "create": false, - "sep": "." -} diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 0ff95f6..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9a34262..0000000 --- a/lib/main.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 015f56b..988c6f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-object-like": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/boolean-ctor": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "2.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..61866bc --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0615992..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 8617f2013d659f34f339b0fc4b73309e97db08c9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 02:57:16 +0000 Subject: [PATCH 029/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a623517..0ff95f6 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -58,7 +58,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 96e37f2..9a34262 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -98,7 +98,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 4538766..a0c3a47 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.x", "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" }, From 693e38d8002e1c51e80f679439086e0c3666818b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 10:12:05 +0000 Subject: [PATCH 030/140] Remove files --- index.d.ts | 180 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4229 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 39cbea0..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 94010c4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport copy from '@stdlib/utils-copy';\nimport validate from './validate.js';\nimport defaults from './defaults.json';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport copy from '@stdlib/utils-copy';\nimport validate from './validate.js';\nimport defaults from './defaults.json';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,2BC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCgBA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CC/DA,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CC1CAU,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 61866bc..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 330f984c9fe03f8fae15ea058f4c208e1f5d20fb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 10:12:55 +0000 Subject: [PATCH 031/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/dset.js | 80 - lib/factory.js | 100 - lib/index.js | 58 - lib/main.js | 121 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4044 +++++++++++++++++++++ test/test.dset.js | 292 -- test/test.factory.js | 221 -- test/test.js | 201 - test/test.validate.js | 132 - 44 files changed, 4073 insertions(+), 4769 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.json delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 919d1eb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T01:16:00.893Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 667222f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a10c773..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..06d866f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..94010c4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport copy from '@stdlib/utils-copy';\nimport validate from './validate.js';\nimport defaults from './defaults.json';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport copy from '@stdlib/utils-copy';\nimport validate from './validate.js';\nimport defaults from './defaults.json';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,2BC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCgBA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CC/DA,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CC1CAU,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 274affc..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "create": false, - "sep": "." -} diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 0ff95f6..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9a34262..0000000 --- a/lib/main.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index a0c3a47..988c6f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-object-like": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/boolean-ctor": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fe5a892 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0615992..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 9894a61625ac529ad0e1219d8b87f0896dc96c9a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 03:51:30 +0000 Subject: [PATCH 032/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index a623517..0ff95f6 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -58,7 +58,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 96e37f2..9a34262 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var validate = require( './validate.js' ); var defaults = require( './defaults.json' ); @@ -98,7 +98,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = copy( defaults ); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 4538766..a0c3a47 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.x", "@stdlib/assert-is-plain-object": "^0.0.x", "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" }, From 549b3a068b4c2c395bd341449eb7a596b1188980 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 17:20:19 +0000 Subject: [PATCH 033/140] Remove files --- index.d.ts | 180 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4229 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 06d866f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 94010c4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport copy from '@stdlib/utils-copy';\nimport validate from './validate.js';\nimport defaults from './defaults.json';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport copy from '@stdlib/utils-copy';\nimport validate from './validate.js';\nimport defaults from './defaults.json';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,2BC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCgBA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CC/DA,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CC1CAU,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fe5a892..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From bf475e710ea41ba945d1725e61f91c0ab1e199a6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 17:21:27 +0000 Subject: [PATCH 034/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 --- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/dset.js | 80 - lib/factory.js | 100 - lib/index.js | 58 - lib/main.js | 121 - lib/validate.js | 74 - package.json | 62 +- stats.html | 6177 +++++++++++++++++++++ test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 44 files changed, 6206 insertions(+), 4769 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.json delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 24a15da..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T01:40:27.734Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 667222f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a10c773..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..06d866f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..94010c4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport copy from '@stdlib/utils-copy';\nimport validate from './validate.js';\nimport defaults from './defaults.json';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport copy from '@stdlib/utils-copy';\nimport validate from './validate.js';\nimport defaults from './defaults.json';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,2BC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCgBA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CC/DA,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CC1CAU,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 274affc..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "create": false, - "sep": "." -} diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 0ff95f6..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9a34262..0000000 --- a/lib/main.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.json' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = copy( defaults ); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index a0c3a47..988c6f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-object-like": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/boolean-ctor": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e12d9b5 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0615992..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 37c3f89d6fbb560752866397aa4237498f5c8af1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 13 Feb 2023 16:39:52 +0000 Subject: [PATCH 035/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..d2db8f8 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..99b4c7f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index b3896ed..5f9ddf1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.8", "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" }, "devDependencies": { From 88758f2d278385e92979f4d0d61de8e039f97e45 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 13 Feb 2023 16:44:49 +0000 Subject: [PATCH 036/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 06d866f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function j(e,s){return d(s)?m(s,"create")&&(e.create=s.create,!o(e.create))?new TypeError(i("0j630","create",e.create)):m(s,"sep")&&(e.sep=s.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",s))}var l={create:!1,sep:"."};function a(e,t,r,i){var n,o,d,j,l;for(o=t.length,n=!1,d=e,l=0;l3&&(h=j(c,m)))throw h;return a(e,p?o.split(c.sep):o,c.create,d)}function h(e,o){var d,m,p,c;if(!(d=t(e))&&!r(e))throw new TypeError(i("0j63M",e));if(p=n(l),arguments.length>1&&(c=j(p,o)))throw c;return m=d?e.split(p.sep):e,h;function h(e,t){return!!s(e)&&a(e,m,p.create,t)}}e(c,"factory",h);export{c as default,h as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 94010c4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport copy from '@stdlib/utils-copy';\nimport validate from './validate.js';\nimport defaults from './defaults.json';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport copy from '@stdlib/utils-copy';\nimport validate from './validate.js';\nimport defaults from './defaults.json';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = copy( defaults );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","copy","defaults","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;85BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,2BC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCgBA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOK,EAAMnB,EALRa,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CC/DA,SAASS,EAASV,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EAAO2B,EAAMC,GACRC,UAAUV,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKS,MAAO/B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXmB,EAAMnB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CC1CAU,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e12d9b5..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fa3c40ea1d0e03df729108730450c20911cea879 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 13 Feb 2023 16:45:33 +0000 Subject: [PATCH 037/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 236 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 43 files changed, 6206 insertions(+), 4931 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 667222f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e345c43 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6699566 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index d2db8f8..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 99b4c7f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 5f9ddf1..a9da203 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-object-like": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/boolean-ctor": "^0.0.1", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..cfdb417 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0615992..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 041dbc3ffd8141985a4dada4ae1c046b84db013a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 01:55:36 +0000 Subject: [PATCH 038/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..d2db8f8 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..99b4c7f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index b3896ed..5f9ddf1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.8", "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" }, "devDependencies": { From 1fcdd01708933fa80656fcbd5aed25a0f3c46242 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 04:46:23 +0000 Subject: [PATCH 039/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e345c43..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6699566..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cfdb417..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From eeff0f926fcd3e64afa25889aa2c6a7a8e002438 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 04:47:06 +0000 Subject: [PATCH 040/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 236 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 44 files changed, 6206 insertions(+), 4936 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5f991ce..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T01:18:58.916Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 667222f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e345c43 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6699566 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index d2db8f8..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 99b4c7f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 5f9ddf1..a9da203 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-object-like": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/boolean-ctor": "^0.0.1", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ff6231e --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0615992..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 5185ee0d22b371b877fe8dc4e808efc8d9295a32 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 01:57:06 +0000 Subject: [PATCH 041/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..d2db8f8 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..99b4c7f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index b3896ed..5f9ddf1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.8", "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" }, "devDependencies": { From 3e756e98aaf491440a5c4842fde2199c97ba8e5e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 04:27:24 +0000 Subject: [PATCH 042/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e345c43..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6699566..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ff6231e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From dfeb5226fb95c61545b2fd3a300c3a51eff6c48a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 04:28:16 +0000 Subject: [PATCH 043/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 44 files changed, 6206 insertions(+), 4942 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index d81a020..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-04-01T01:21:56.892Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 667222f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e345c43 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6699566 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index d2db8f8..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 99b4c7f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 5f9ddf1..a9da203 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-object-like": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/boolean-ctor": "^0.0.1", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b7e786f --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0615992..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 28c5bdfd3396df91d7fa1aadf069f63d014105a2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 01:53:43 +0000 Subject: [PATCH 044/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..d2db8f8 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..99b4c7f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index b3896ed..5f9ddf1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.8", "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" }, "devDependencies": { From daea7ca76e8b9a85d213ef44f1865f2d8752ebf4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 04:19:25 +0000 Subject: [PATCH 045/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e345c43..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6699566..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b7e786f..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fedaa3911b77e6fe3599acd866914bd43585a98b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 04:20:08 +0000 Subject: [PATCH 046/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 44 files changed, 6206 insertions(+), 4942 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4762b26..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-05-01T01:19:47.967Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 667222f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e345c43 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6699566 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index d2db8f8..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 99b4c7f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 5f9ddf1..a9da203 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-object-like": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/boolean-ctor": "^0.0.1", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f384673 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0615992..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 2ad3ac21b4a98ebb8470a937b67506647b602f67 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 01:56:20 +0000 Subject: [PATCH 047/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..d2db8f8 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..99b4c7f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index b3896ed..5f9ddf1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.8", "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" }, "devDependencies": { From 4d6246e506059e117ef72564c180691ee7f14049 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 04:35:53 +0000 Subject: [PATCH 048/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e345c43..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6699566..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f384673..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 587510dac19e6d3475bbfbaeea3f2f1b3eae5972 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 04:36:52 +0000 Subject: [PATCH 049/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 44 files changed, 6206 insertions(+), 4942 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 76d89e6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T01:22:10.953Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 667222f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e345c43 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6699566 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index d2db8f8..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 99b4c7f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 5f9ddf1..a9da203 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-object-like": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/boolean-ctor": "^0.0.1", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e85a7fa --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0615992..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 12ec9e8585799f2fcf434fddd227ff141bd435eb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 01:56:32 +0000 Subject: [PATCH 050/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..d2db8f8 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..99b4c7f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index b3896ed..5f9ddf1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.8", "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" }, "devDependencies": { From 6b36ad0f11af939cf442207356e19dcbf185a8d4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 04:32:38 +0000 Subject: [PATCH 051/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e345c43..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6699566..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e85a7fa..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ad75ff7580da6eef0f919b7f3935856571bc7a43 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 04:33:32 +0000 Subject: [PATCH 052/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 44 files changed, 6206 insertions(+), 4942 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index fe9ddd3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T01:22:19.129Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 667222f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e345c43 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6699566 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index d2db8f8..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 99b4c7f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 5f9ddf1..a9da203 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-object-like": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/boolean-ctor": "^0.0.1", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ea89c64 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 1d450d4..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 6aeafd4..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3f62a04..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0615992..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 8cc382527bf263f348e521c6961c774d8829b472 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 02:00:06 +0000 Subject: [PATCH 053/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..d2db8f8 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..99b4c7f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '0j63M', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..0fe0188 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0j62h', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '0j630', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '0j62i', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index b3896ed..5f9ddf1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.0.8", "@stdlib/assert-is-plain-object": "^0.0.7", "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" }, "devDependencies": { From e6f18b89e618a94c6562c8bb7a60e5ab9114e2a9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 04:38:30 +0000 Subject: [PATCH 054/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e345c43..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6699566..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ea89c64..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4f76ec11717a3d4fde3c80d65a496c50c0639c37 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 04:39:20 +0000 Subject: [PATCH 055/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 44 files changed, 6206 insertions(+), 4942 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index d24dedb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-08-01T01:23:01.312Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 667222f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 334eb59..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -285,7 +284,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -347,9 +346,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e345c43 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6699566 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index d2db8f8..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 99b4c7f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '0j63M', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0fe0188..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '0j62h', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '0j630', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '0j62i', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 5f9ddf1..a9da203 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-object-like": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/boolean-ctor": "^0.0.1", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d467315 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 4e41e576d0dbe01b7ab6deb3bc79a95f57ec96c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 22:18:05 +0000 Subject: [PATCH 056/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..19b1cd5 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A,It', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..2f4bfa4 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A,It', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..1e41439 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V,FD', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o,GE', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 3b6b819..d93b4ea 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.1.0", "@stdlib/assert-is-plain-object": "^0.1.0", "@stdlib/assert-is-string": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" }, "devDependencies": { From f43056d0a4212a32da57a5929d5cd947dc2cc38d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 22:19:36 +0000 Subject: [PATCH 057/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 1230c6e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e345c43..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("0j630","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("0j62i","sep",e.sep)):null:new TypeError(i("0j62h",r))}function j(e,t,s,i){var n,o,m,j,l;for(o=t.length,n=!1,m=e,l=0;l3&&(a=m(l,p)))throw a;return j(e,d?n.split(l.sep):n,l.create,o)}function a(e,n){var o,p,d,l;if(!(o=t(e))&&!s(e))throw new TypeError(i("0j63M",e));if(d={create:!1,sep:"."},arguments.length>1&&(l=m(d,n)))throw l;return p=o?e.split(d.sep):e,a;function a(e,t){return!!r(e)&&j(e,p,d.create,t)}}e(l,"factory",a);export{l as default,a as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6699566..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0j62h', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '0j630', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '0j62i', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '0j63M', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;g1BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d467315..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5bedcf5888dd395a67d663bfc0bd64761597d4e0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 22:20:38 +0000 Subject: [PATCH 058/140] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 47 files changed, 6206 insertions(+), 4985 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 3426cd2..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 667222f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -296,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -358,9 +357,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6ab86dc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";function m(e,t){return o(t)?p(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("1SV2o,GE","create",e.create)):p(t,"sep")&&(e.sep=t.sep,!r(e.sep))?new TypeError(i("1SV2W,Gh","sep",e.sep)):null:new TypeError(i("1SV2V,FD",t))}function l(e,r,s,i){var n,o,m,l,a;for(o=r.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=r(e))&&!s(e))throw new TypeError(i("1SV3A,It",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,j;function j(e,r){return!!t(e)&&l(e,p,d.create,r)}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..291d623 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V,FD', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o,GE', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;i4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUP,EAAKI,SAGtDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,WAAY,MAAOP,EAAKQ,MAGjD,KAdC,IAAIF,UAAWC,EAAQ,WAAYN,GAe5C,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 19b1cd5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A,It', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2f4bfa4..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A,It', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 1e41439..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V,FD', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o,GE', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index d93b4ea..7526d34 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/assert-is-object-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.0", - "@stdlib/assert-is-string": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/boolean-ctor": "^0.1.0", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0c047ff --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 6783df6f5e9082531900edb753f04556df98c304 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 22:20:58 +0000 Subject: [PATCH 059/140] Update README.md for ESM bundle v0.1.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7978722..a13e69a 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import deepSet from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@esm/index.mjs'; +import deepSet from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@v0.1.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@v0.1.0-esm/index.mjs'; ``` #### deepSet( obj, path, value\[, options] ) @@ -233,7 +233,7 @@ console.log( obj ); - - - - From 2f5056d03ce13b7eaa7e417d2ad3eacd6b2e7d60 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 18:59:38 +0000 Subject: [PATCH 063/140] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 201 - test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 49 files changed, 6206 insertions(+), 5245 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 0acd3a7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T01:11:18.596Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 033f12b..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -296,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -358,9 +357,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1fd3028 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";function m(e,t){return o(t)?p(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("1SV2o,GE","create",e.create)):p(t,"sep")&&(e.sep=t.sep,!r(e.sep))?new TypeError(i("1SV2W,Gh","sep",e.sep)):null:new TypeError(i("1SV2V,FD",t))}function l(e,r,s,i){var n,o,m,l,a;for(o=r.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=r(e))&&!s(e))throw new TypeError(i("1SV3A,It",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,j;function j(e,r){return!!t(e)&&l(e,p,d.create,r)}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fae40c7 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V,FD', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o,GE', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUP,EAAKI,SAGtDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,WAAY,MAAOP,EAAKQ,MAGjD,KAdC,IAAIF,UAAWC,EAAQ,WAAYN,GAe5C,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 19b1cd5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A,It', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2f4bfa4..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A,It', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 1e41439..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V,FD', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o,GE', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 50baa16..7526d34 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/assert-is-object-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.0", - "@stdlib/assert-is-string": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/boolean-ctor": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..781eef7 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 8c60c0c..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 4d1bf94dd082cec867fe5654320bb84cab7a64d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 01:38:30 +0000 Subject: [PATCH 064/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..19b1cd5 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A,It', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..2f4bfa4 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A,It', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..1e41439 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V,FD', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o,GE', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index a18ae98..78cd280 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.1.1", "@stdlib/assert-is-plain-object": "^0.1.1", "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" }, "devDependencies": { From 50d6aba56bc848ed11afe63524424e0d2b5d395f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 10:33:22 +0000 Subject: [PATCH 065/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7866047..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1fd3028..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";function m(e,t){return o(t)?p(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("1SV2o,GE","create",e.create)):p(t,"sep")&&(e.sep=t.sep,!r(e.sep))?new TypeError(i("1SV2W,Gh","sep",e.sep)):null:new TypeError(i("1SV2V,FD",t))}function l(e,r,s,i){var n,o,m,l,a;for(o=r.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=r(e))&&!s(e))throw new TypeError(i("1SV3A,It",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,j;function j(e,r){return!!t(e)&&l(e,p,d.create,r)}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index fae40c7..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V,FD', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o,GE', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUP,EAAKI,SAGtDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,WAAY,MAAOP,EAAKQ,MAGjD,KAdC,IAAIF,UAAWC,EAAQ,WAAYN,GAe5C,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 781eef7..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f78ee77b9a665dcbf4c69c69bf4d7da78cb9e2b3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 10:36:47 +0000 Subject: [PATCH 066/140] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 201 - test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 48 files changed, 6206 insertions(+), 5244 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 033f12b..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -296,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -358,9 +357,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c11c811 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";function m(e,t){return o(t)?p(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("1SV2o,GE","create",e.create)):p(t,"sep")&&(e.sep=t.sep,!r(e.sep))?new TypeError(i("1SV2W,Gh","sep",e.sep)):null:new TypeError(i("1SV2V,FD",t))}function l(e,r,s,i){var n,o,m,l,a;for(o=r.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=r(e))&&!s(e))throw new TypeError(i("1SV3A,It",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,j;function j(e,r){return!!t(e)&&l(e,p,d.create,r)}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fae40c7 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V,FD', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o,GE', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUP,EAAKI,SAGtDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,WAAY,MAAOP,EAAKQ,MAGjD,KAdC,IAAIF,UAAWC,EAAQ,WAAYN,GAe5C,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 19b1cd5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A,It', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2f4bfa4..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A,It', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 1e41439..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V,FD', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o,GE', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 78cd280..56a6531 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-object-like": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/boolean-ctor": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4b90bf8 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 8c60c0c..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 38480b22f1de8b8215e7e56215dab42f4d57d9fd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 15:35:01 +0000 Subject: [PATCH 067/140] Update README.md for ESM bundle v0.1.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c8fdd4b..2dd18c2 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import deepSet from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@esm/index.mjs'; +import deepSet from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@v0.1.1-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@v0.1.1-esm/index.mjs'; ``` #### deepSet( obj, path, value\[, options] ) @@ -233,7 +233,7 @@ console.log( obj ); - - - - From 8ef83940b88d61c8854bfd5eaac80257d46ef2bf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 19:13:07 +0000 Subject: [PATCH 071/140] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 201 - test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 48 files changed, 6206 insertions(+), 5244 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 033f12b..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -296,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -358,9 +357,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3cc4752 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";function m(e,t){return o(t)?p(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("1SV2o,GE","create",e.create)):p(t,"sep")&&(e.sep=t.sep,!r(e.sep))?new TypeError(i("1SV2W,Gh","sep",e.sep)):null:new TypeError(i("1SV2V,FD",t))}function l(e,r,s,i){var n,o,m,l,a;for(o=r.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=r(e))&&!s(e))throw new TypeError(i("1SV3A,It",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,j;function j(e,r){return!!t(e)&&l(e,p,d.create,r)}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fae40c7 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V,FD', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o,GE', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUP,EAAKI,SAGtDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,WAAY,MAAOP,EAAKQ,MAGjD,KAdC,IAAIF,UAAWC,EAAQ,WAAYN,GAe5C,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 19b1cd5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A,It', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2f4bfa4..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A,It', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 1e41439..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V,FD', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o,GE', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index c9bc9cd..56a6531 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-object-like": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/boolean-ctor": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2ac48cb --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 8c60c0c..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From dcc71d37d7f4ee12f9411cdc0a63dfcbafca6527 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 02:14:32 +0000 Subject: [PATCH 072/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..19b1cd5 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A,It', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..2f4bfa4 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A,It', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..1e41439 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V,FD', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o,GE', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 3102d20..c9bc9cd 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.1.1", "@stdlib/assert-is-plain-object": "^0.1.1", "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" }, "devDependencies": { From 481f45d8cbd5fbdf402efa3975e6fd82568f3381 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 19:20:18 +0000 Subject: [PATCH 073/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7866047..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3cc4752..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";function m(e,t){return o(t)?p(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("1SV2o,GE","create",e.create)):p(t,"sep")&&(e.sep=t.sep,!r(e.sep))?new TypeError(i("1SV2W,Gh","sep",e.sep)):null:new TypeError(i("1SV2V,FD",t))}function l(e,r,s,i){var n,o,m,l,a;for(o=r.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=r(e))&&!s(e))throw new TypeError(i("1SV3A,It",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,j;function j(e,r){return!!t(e)&&l(e,p,d.create,r)}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index fae40c7..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V,FD', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o,GE', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUP,EAAKI,SAGtDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,WAAY,MAAOP,EAAKQ,MAGjD,KAdC,IAAIF,UAAWC,EAAQ,WAAYN,GAe5C,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2ac48cb..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5bccc818819595ab3b6f1e7a700bc5fb2a82a9b8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 19:24:04 +0000 Subject: [PATCH 074/140] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 49 files changed, 6206 insertions(+), 5085 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f55f0e9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T01:11:51.005Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 033f12b..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -296,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -358,9 +357,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3cc4752 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";function m(e,t){return o(t)?p(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("1SV2o,GE","create",e.create)):p(t,"sep")&&(e.sep=t.sep,!r(e.sep))?new TypeError(i("1SV2W,Gh","sep",e.sep)):null:new TypeError(i("1SV2V,FD",t))}function l(e,r,s,i){var n,o,m,l,a;for(o=r.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=r(e))&&!s(e))throw new TypeError(i("1SV3A,It",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,j;function j(e,r){return!!t(e)&&l(e,p,d.create,r)}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fae40c7 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V,FD', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o,GE', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUP,EAAKI,SAGtDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,WAAY,MAAOP,EAAKQ,MAGjD,KAdC,IAAIF,UAAWC,EAAQ,WAAYN,GAe5C,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 19b1cd5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A,It', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2f4bfa4..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A,It', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 1e41439..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V,FD', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o,GE', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index c9bc9cd..56a6531 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-object-like": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/boolean-ctor": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..07db873 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 93dff95031a7f5328af77f2829364b8b16ed7248 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 02:12:08 +0000 Subject: [PATCH 075/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..19b1cd5 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A,It', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..2f4bfa4 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A,It', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..1e41439 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V,FD', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o,GE', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 174ef8b..d2647ac 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.1.1", "@stdlib/assert-is-plain-object": "^0.1.1", "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" }, "devDependencies": { From 49d9c3a4cf5d11ddaad639eda19f2f055739cfab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 11:00:11 +0000 Subject: [PATCH 076/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 7866047..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; // tslint-disable-line max-line-length - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3cc4752..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";function m(e,t){return o(t)?p(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("1SV2o,GE","create",e.create)):p(t,"sep")&&(e.sep=t.sep,!r(e.sep))?new TypeError(i("1SV2W,Gh","sep",e.sep)):null:new TypeError(i("1SV2V,FD",t))}function l(e,r,s,i){var n,o,m,l,a;for(o=r.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=r(e))&&!s(e))throw new TypeError(i("1SV3A,It",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,j;function j(e,r){return!!t(e)&&l(e,p,d.create,r)}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index fae40c7..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V,FD', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o,GE', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUP,EAAKI,SAGtDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,WAAY,MAAOP,EAAKQ,MAGjD,KAdC,IAAIF,UAAWC,EAAQ,WAAYN,GAe5C,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 07db873..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 95362ead0535515dae05368b61d90009c8860049 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 11:02:41 +0000 Subject: [PATCH 077/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- benchmark/benchmark.js | 140 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 49 files changed, 6206 insertions(+), 5080 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index fe66c98..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T01:15:53.705Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 033f12b..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -296,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -358,9 +357,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2a4ee60..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3cc4752 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";function m(e,t){return o(t)?p(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("1SV2o,GE","create",e.create)):p(t,"sep")&&(e.sep=t.sep,!r(e.sep))?new TypeError(i("1SV2W,Gh","sep",e.sep)):null:new TypeError(i("1SV2V,FD",t))}function l(e,r,s,i){var n,o,m,l,a;for(o=r.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=r(e))&&!s(e))throw new TypeError(i("1SV3A,It",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,j;function j(e,r){return!!t(e)&&l(e,p,d.create,r)}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fae40c7 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V,FD', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o,GE', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUP,EAAKI,SAGtDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,WAAY,MAAOP,EAAKQ,MAGjD,KAdC,IAAIF,UAAWC,EAAQ,WAAYN,GAe5C,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 19b1cd5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A,It', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2f4bfa4..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A,It', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 1e41439..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V,FD', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o,GE', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index d2647ac..56a6531 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-object-like": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/bench": "^0.2.1", - "@stdlib/boolean-ctor": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d112e4d --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From abf8eb1cfcb58f386affa16c625b22cda2285744 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 01:50:59 +0000 Subject: [PATCH 078/140] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5b078d9..ff28426 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.1.1", "@stdlib/assert-is-plain-object": "^0.1.1", "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" }, "devDependencies": { From f3bcd1d86b4e18b401951accd6ee60a6e42c77b2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 04:50:48 +0000 Subject: [PATCH 079/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3cc4752..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";function m(e,t){return o(t)?p(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("1SV2o,GE","create",e.create)):p(t,"sep")&&(e.sep=t.sep,!r(e.sep))?new TypeError(i("1SV2W,Gh","sep",e.sep)):null:new TypeError(i("1SV2V,FD",t))}function l(e,r,s,i){var n,o,m,l,a;for(o=r.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=r(e))&&!s(e))throw new TypeError(i("1SV3A,It",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,j;function j(e,r){return!!t(e)&&l(e,p,d.create,r)}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index fae40c7..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V,FD', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o,GE', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W,Gh', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A,It', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,WAAY,SAAUP,EAAKI,SAGtDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,WAAY,MAAOP,EAAKQ,MAGjD,KAdC,IAAIF,UAAWC,EAAQ,WAAYN,GAe5C,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,WAAYe,IAG1C,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d112e4d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e2f06b1544cbc9d5ccca4765aa77ba21395fa3fe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 04:51:12 +0000 Subject: [PATCH 080/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 50 files changed, 6206 insertions(+), 5086 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index a696049..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T01:09:07.972Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 52093a1..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -296,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -358,9 +357,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index edcf724..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index a66e3bc..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..edec4ef --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";function m(e,t){return o(t)?a(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("invalid option. `%s` option must be a boolean. Option: `%s`.","create",e.create)):a(t,"sep")&&(e.sep=t.sep,!s(e.sep))?new TypeError(i("invalid option. `%s` option must be a string. Option: `%s`.","sep",e.sep)):null:new TypeError(i("invalid argument. Options argument must be an object. Value: `%s`.",t))}function d(e,s,r,i){var n,o,m,d,l;for(o=s.length,n=!1,m=e,l=0;l3&&(j=m(l,a)))throw j;return d(e,p?n.split(l.sep):n,l.create,o)}function j(e,n){var o,a,p,l;if(!(o=s(e))&&!r(e))throw new TypeError(i("invalid argument. Key path must be a string or a key array. Value: `%s`.",e));if(p={create:!1,sep:"."},arguments.length>1&&(l=m(p,n)))throw l;return a=o?e.split(p.sep):e,j;function j(e,s){return!!t(e)&&d(e,a,p.create,s)}}e(l,"factory",j);export{l as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..3c447da --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;+3BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,+DAAgE,SAAUP,EAAKI,SAG1GD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,8DAA+D,MAAOP,EAAKQ,MAGpG,KAdC,IAAIF,UAAWC,EAAQ,qEAAsEN,GAetG,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,2EAA4Ee,IAG1G,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,2EAA4Ee,IAG1G,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 215ece5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8442b0e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 356d06a..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ff28426..56a6531 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-object-like": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f4fb3c9 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 3679193a74c6ab4576398e74cf64600857faca00 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 01:52:26 +0000 Subject: [PATCH 081/140] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5b078d9..ff28426 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.1.1", "@stdlib/assert-is-plain-object": "^0.1.1", "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" }, "devDependencies": { From e12579aba6ab7c3a3680cb3bfde5dad1c8a44c4a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 04:01:16 +0000 Subject: [PATCH 082/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index edec4ef..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";function m(e,t){return o(t)?a(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("invalid option. `%s` option must be a boolean. Option: `%s`.","create",e.create)):a(t,"sep")&&(e.sep=t.sep,!s(e.sep))?new TypeError(i("invalid option. `%s` option must be a string. Option: `%s`.","sep",e.sep)):null:new TypeError(i("invalid argument. Options argument must be an object. Value: `%s`.",t))}function d(e,s,r,i){var n,o,m,d,l;for(o=s.length,n=!1,m=e,l=0;l3&&(j=m(l,a)))throw j;return d(e,p?n.split(l.sep):n,l.create,o)}function j(e,n){var o,a,p,l;if(!(o=s(e))&&!r(e))throw new TypeError(i("invalid argument. Key path must be a string or a key array. Value: `%s`.",e));if(p={create:!1,sep:"."},arguments.length>1&&(l=m(p,n)))throw l;return a=o?e.split(p.sep):e,j;function j(e,s){return!!t(e)&&d(e,a,p.create,s)}}e(l,"factory",j);export{l as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 3c447da..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;+3BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,+DAAgE,SAAUP,EAAKI,SAG1GD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,8DAA+D,MAAOP,EAAKQ,MAGpG,KAdC,IAAIF,UAAWC,EAAQ,qEAAsEN,GAetG,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,2EAA4Ee,IAG1G,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,2EAA4Ee,IAG1G,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f4fb3c9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 216b8ead64923d81fba01f75a5e629cae21f810a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 04:01:45 +0000 Subject: [PATCH 083/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 50 files changed, 6206 insertions(+), 5091 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 22d8393..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T01:16:02.564Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 52093a1..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index edcf724..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..edec4ef --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";function m(e,t){return o(t)?a(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("invalid option. `%s` option must be a boolean. Option: `%s`.","create",e.create)):a(t,"sep")&&(e.sep=t.sep,!s(e.sep))?new TypeError(i("invalid option. `%s` option must be a string. Option: `%s`.","sep",e.sep)):null:new TypeError(i("invalid argument. Options argument must be an object. Value: `%s`.",t))}function d(e,s,r,i){var n,o,m,d,l;for(o=s.length,n=!1,m=e,l=0;l3&&(j=m(l,a)))throw j;return d(e,p?n.split(l.sep):n,l.create,o)}function j(e,n){var o,a,p,l;if(!(o=s(e))&&!r(e))throw new TypeError(i("invalid argument. Key path must be a string or a key array. Value: `%s`.",e));if(p={create:!1,sep:"."},arguments.length>1&&(l=m(p,n)))throw l;return a=o?e.split(p.sep):e,j;function j(e,s){return!!t(e)&&d(e,a,p.create,s)}}e(l,"factory",j);export{l as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..3c447da --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;+3BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,+DAAgE,SAAUP,EAAKI,SAG1GD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,8DAA+D,MAAOP,EAAKQ,MAGpG,KAdC,IAAIF,UAAWC,EAAQ,qEAAsEN,GAetG,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,2EAA4Ee,IAG1G,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,2EAA4Ee,IAG1G,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 215ece5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8442b0e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 356d06a..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ff28426..56a6531 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-object-like": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..772215b --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From ba15efd62caa3ef996817ad84223ecbfb06eb40e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 04:44:05 +0000 Subject: [PATCH 084/140] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 951be22..bf2da34 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.0", "@stdlib/assert-is-plain-object": "^0.2.0", "@stdlib/assert-is-string": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0" }, "devDependencies": { From f90a296a902f515f81569550a048fde0060a3d94 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 06:46:56 +0000 Subject: [PATCH 085/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6362 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index edec4ef..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";function m(e,t){return o(t)?a(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("invalid option. `%s` option must be a boolean. Option: `%s`.","create",e.create)):a(t,"sep")&&(e.sep=t.sep,!s(e.sep))?new TypeError(i("invalid option. `%s` option must be a string. Option: `%s`.","sep",e.sep)):null:new TypeError(i("invalid argument. Options argument must be an object. Value: `%s`.",t))}function d(e,s,r,i){var n,o,m,d,l;for(o=s.length,n=!1,m=e,l=0;l3&&(j=m(l,a)))throw j;return d(e,p?n.split(l.sep):n,l.create,o)}function j(e,n){var o,a,p,l;if(!(o=s(e))&&!r(e))throw new TypeError(i("invalid argument. Key path must be a string or a key array. Value: `%s`.",e));if(p={create:!1,sep:"."},arguments.length>1&&(l=m(p,n)))throw l;return a=o?e.split(p.sep):e,j;function j(e,s){return!!t(e)&&d(e,a,p.create,s)}}e(l,"factory",j);export{l as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 3c447da..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;+3BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,+DAAgE,SAAUP,EAAKI,SAG1GD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,8DAA+D,MAAOP,EAAKQ,MAGpG,KAdC,IAAIF,UAAWC,EAAQ,qEAAsEN,GAetG,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,2EAA4Ee,IAG1G,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,2EAA4Ee,IAG1G,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 772215b..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ea88adab89a55fe9b8d1ff13ab01614e641d2279 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 06:47:28 +0000 Subject: [PATCH 086/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 - test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 49 files changed, 6206 insertions(+), 5094 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 81bbe4d..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index edcf724..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6109be1 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.1.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";function m(e,t){return o(t)?a(t,"create")&&(e.create=t.create,!n(e.create))?new TypeError(i("invalid option. `%s` option must be a boolean. Option: `%s`.","create",e.create)):a(t,"sep")&&(e.sep=t.sep,!s(e.sep))?new TypeError(i("invalid option. `%s` option must be a string. Option: `%s`.","sep",e.sep)):null:new TypeError(i("invalid argument. Options argument must be an object. Value: `%s`.",t))}function d(e,s,r,i){var n,o,m,d,l;for(o=s.length,n=!1,m=e,l=0;l3&&(j=m(l,a)))throw j;return d(e,p?n.split(l.sep):n,l.create,o)}function j(e,n){var o,a,p,l;if(!(o=s(e))&&!r(e))throw new TypeError(i("invalid argument. Key path must be a string or a key array. Value: `%s`.",e));if(p={create:!1,sep:"."},arguments.length>1&&(l=m(p,n)))throw l;return a=o?e.split(p.sep):e,j;function j(e,s){return!!t(e)&&d(e,a,p.create,s)}}e(l,"factory",j);export{l as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..3c447da --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/string-format';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;+3BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,+DAAgE,SAAUP,EAAKI,SAG1GD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,8DAA+D,MAAOP,EAAKQ,MAGpG,KAdC,IAAIF,UAAWC,EAAQ,qEAAsEN,GAetG,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,2EAA4Ee,IAG1G,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,2EAA4Ee,IAG1G,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEFZ,EAcP,SAASA,EAASC,EAAKY,GACtB,QAAKH,EAAcT,IACXiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,EAGvC,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 215ece5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8442b0e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 356d06a..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index bf2da34..2aed3ad 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.2.0", - "@stdlib/assert-is-boolean": "^0.2.0", - "@stdlib/assert-is-function": "^0.2.0", - "@stdlib/assert-is-object-like": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/assert-is-string": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..797b4ef --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 3921a671485780f8ae50df1086e0346d547b37b1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 08:39:43 +0000 Subject: [PATCH 087/140] Update README.md for ESM bundle v0.2.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 411ee86..d8827a0 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import deepSet from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@esm/index.mjs'; +import deepSet from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@v0.2.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@v0.2.0-esm/index.mjs'; ``` #### deepSet( obj, path, value\[, options] ) @@ -233,7 +233,7 @@ console.log( obj ); - - - - From 99ac6c4ff80b5c8019d649c486541b7217b024a6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 22 Feb 2024 02:54:25 +0000 Subject: [PATCH 091/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 61 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 49 files changed, 4871 insertions(+), 5088 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index edcf724..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b3512c0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 188a90e..bfa9934 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-object-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5d22f96 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 9fcaa8511e3cbe216fc0cf5c8aaa9450bbadc7bd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 22 Feb 2024 03:30:41 +0000 Subject: [PATCH 092/140] Update README.md for ESM bundle v0.2.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6b822c8..b701e08 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import deepSet from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@esm/index.mjs'; +import deepSet from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@v0.2.1-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@v0.2.1-esm/index.mjs'; ``` #### deepSet( obj, path, value\[, options] ) @@ -233,7 +233,7 @@ console.log( obj ); - - - - From 16d1f431ccc3120ae00a9d4d6c42a79ebb85d82a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 03:01:40 +0000 Subject: [PATCH 096/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 50 files changed, 4871 insertions(+), 5091 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b7440ad..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T01:15:17.835Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index edcf724..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5612839 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 717f992..bfa9934 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-object-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..84d4ae9 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From c2adb17f9a64857c7ea171c8804f4732c72d29f1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 01:29:39 +0000 Subject: [PATCH 097/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..9c6d806 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..e1addda 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..573112b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 81c485b..717f992 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.1", "@stdlib/assert-is-plain-object": "^0.2.1", "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From c33e6c8013c67b23a11dd75ad0f05e18491a72a3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 03:15:43 +0000 Subject: [PATCH 098/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5027 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5612839..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2b7a972..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 84d4ae9..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 89b640df375a0902e52bcb142cd335dbecc3788c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 03:15:56 +0000 Subject: [PATCH 099/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 50 files changed, 4871 insertions(+), 5094 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index a508892..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T01:06:32.170Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index edcf724..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5612839 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 717f992..bfa9934 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-object-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..84d4ae9 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 286af87ade55c850b00643e720b9c107418fc028 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 21:35:57 +0000 Subject: [PATCH 100/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..9c6d806 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..e1addda 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..573112b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 81c485b..717f992 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.1", "@stdlib/assert-is-plain-object": "^0.2.1", "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From f9f76dc11d0c0da67f4c9fbad0e76a991a668a33 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 23:17:02 +0000 Subject: [PATCH 101/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5027 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5612839..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2b7a972..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 84d4ae9..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b35141bf2ddd1db5fdd06cdaf0ded44e30cb8e5e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 23:17:18 +0000 Subject: [PATCH 102/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 49 files changed, 4871 insertions(+), 5095 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index edcf724..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5612839 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 717f992..bfa9934 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-object-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..84d4ae9 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From a619e48d10fc5169e71c02e04625adff41d1b037 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 01:31:15 +0000 Subject: [PATCH 103/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..9c6d806 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..e1addda 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..573112b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 81c485b..717f992 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.1", "@stdlib/assert-is-plain-object": "^0.2.1", "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 0eeb81aa78bb2d00850b49e099f80ba6bbd8e444 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 03:01:08 +0000 Subject: [PATCH 104/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5027 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5612839..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2b7a972..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 84d4ae9..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From edd6db47973c926054c0192862eb29567d215dc3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 03:01:27 +0000 Subject: [PATCH 105/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 248 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 50 files changed, 4871 insertions(+), 5103 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8febf39..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-05-01T01:07:09.106Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index edcf724..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should succesfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5612839 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 717f992..bfa9934 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-object-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..84d4ae9 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From d4e6e5ea95e1d9995c12291b91019847dec1d920 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 4 May 2024 20:40:26 +0000 Subject: [PATCH 106/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..9c6d806 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..e1addda 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..573112b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 81c485b..717f992 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.1", "@stdlib/assert-is-plain-object": "^0.2.1", "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From e4d3ded45841fa9acfe255587a9453ba9738634b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 4 May 2024 20:41:09 +0000 Subject: [PATCH 107/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5027 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5612839..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2b7a972..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 84d4ae9..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b719ddc75fda1ff67f443b40f43ab22a023f6926 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 4 May 2024 20:41:25 +0000 Subject: [PATCH 108/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 248 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 49 files changed, 4871 insertions(+), 5102 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 681b7a1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5612839 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 717f992..bfa9934 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-object-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..84d4ae9 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 6700e52643cd648ccb0cd5bb49a0e90630e5098b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 01:37:44 +0000 Subject: [PATCH 109/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..9c6d806 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..e1addda 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..573112b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 81c485b..717f992 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.1", "@stdlib/assert-is-plain-object": "^0.2.1", "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 9ca0e83d01daf768cf7941640103c666e6a12ff6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 02:53:24 +0000 Subject: [PATCH 110/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5027 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5612839..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2b7a972..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 84d4ae9..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d5e3bf2eb3ca7ef2edb67ebeabcd4cc2ee7c3944 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 02:53:39 +0000 Subject: [PATCH 111/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 248 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 50 files changed, 4871 insertions(+), 5103 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index dbed007..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-06-01T01:16:40.969Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 681b7a1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5612839 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 717f992..bfa9934 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-object-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..84d4ae9 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From e2596f924d14b79fb73e89c04787df9b106b6ae5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 01:36:27 +0000 Subject: [PATCH 112/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..9c6d806 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..e1addda 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..573112b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 81c485b..717f992 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.1", "@stdlib/assert-is-plain-object": "^0.2.1", "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From ab45c9cb2d3ac19e45bebc20998a7a8b0e76418c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 02:54:53 +0000 Subject: [PATCH 113/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5027 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5612839..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2b7a972..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 84d4ae9..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2d6690fcfb3f8a018cb6f42572a3155058237ee2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 02:55:14 +0000 Subject: [PATCH 114/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 38 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 50 files changed, 4871 insertions(+), 5140 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index a76cd0b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-07-01T01:15:00.102Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 681b7a1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5612839 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 717f992..bfa9934 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-object-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..84d4ae9 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 79d1c0f96b00937a0f2e498e66c359ecfa7b0f9e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 01:01:33 +0000 Subject: [PATCH 115/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..9c6d806 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..e1addda 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..573112b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index 9ee6611..66d1d9a 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.1", "@stdlib/assert-is-plain-object": "^0.2.1", "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 781a92b0346204952b1d2373bcf2047c895dfb75 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 01:24:49 +0000 Subject: [PATCH 116/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5027 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5612839..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2b7a972..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 84d4ae9..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8cb27a276fd930c92a29b76b3e69c0763c640fc7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 01:25:07 +0000 Subject: [PATCH 117/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 220 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 49 files changed, 4871 insertions(+), 5321 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 681b7a1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7de0714 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 66d1d9a..0284762 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-object-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e2ac0c6 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 34317b73185d0dfe4855fb8c062eb98958a9980c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 01:30:40 +0000 Subject: [PATCH 118/140] Update README.md for ESM bundle v0.2.2 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dff5f86..546a1c1 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import deepSet from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@esm/index.mjs'; +import deepSet from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@v0.2.2-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-deep-set@v0.2.2-esm/index.mjs'; ``` #### deepSet( obj, path, value\[, options] ) @@ -233,7 +233,7 @@ console.log( obj ); - - - - From d4060656f02ee896bc4824d2760d6a162dea26d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 03:11:56 +0000 Subject: [PATCH 122/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 158 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 50 files changed, 4871 insertions(+), 5262 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5e8cbcb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T01:17:54.557Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 681b7a1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..df702f6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f6ad23b..0284762 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-object-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2ae3891 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From e7ff5b16788ab7f95ac4caf661ed57ce4f954e19 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 16:19:39 +0000 Subject: [PATCH 123/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..9c6d806 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..e1addda 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..573112b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index d950d62..f6ad23b 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 71dd7f6c0b1aad21f56a631c22e5da56c7e0abc7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 17:17:14 +0000 Subject: [PATCH 124/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5027 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index df702f6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2b7a972..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2ae3891..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cdceb5a0e2279a54c505d8da2789f2aef6d2bc63 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 17:17:28 +0000 Subject: [PATCH 125/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 220 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 50 files changed, 4871 insertions(+), 5324 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ddd5cf6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-03T16:02:29.440Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 681b7a1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..df702f6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f6ad23b..0284762 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-object-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2ae3891 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 3933067642369dc897d8d8d12608b415fc684b3b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 01:47:29 +0000 Subject: [PATCH 126/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..9c6d806 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..e1addda 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..573112b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index d950d62..f6ad23b 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 6c51491f894d89db303b07b57e89ff746954e958 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 03:10:39 +0000 Subject: [PATCH 127/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5027 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index df702f6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2b7a972..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2ae3891..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 80179536db4fe935b4645573dac1ab492fc323a8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 03:10:52 +0000 Subject: [PATCH 128/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 219 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 50 files changed, 4871 insertions(+), 5323 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 6fb1403..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T01:24:47.494Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 681b7a1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..df702f6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f6ad23b..0284762 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-object-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2ae3891 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 9dc6502beb5d4edff6dd6a429265071f53247ddb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 01:51:22 +0000 Subject: [PATCH 129/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..9c6d806 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..e1addda 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..573112b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index d950d62..f6ad23b 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 4b3b84fe71c06e34c8ae138aa6273fad7c3dc100 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 03:10:51 +0000 Subject: [PATCH 130/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5027 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index df702f6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2b7a972..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2ae3891..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e44a2d223b385a53d17bf859184ecc8fe96d87a2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 03:11:04 +0000 Subject: [PATCH 131/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 219 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 50 files changed, 4871 insertions(+), 5323 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f374f71..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T01:30:54.305Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 681b7a1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..df702f6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f6ad23b..0284762 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-object-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2ae3891 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From dd4093393b32da2816c66613e7efaa6da9f5f079 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 01:47:45 +0000 Subject: [PATCH 132/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..9c6d806 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..e1addda 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..573112b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index d950d62..f6ad23b 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From a886bf61909c010cb629c5c641160931a932dc29 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 03:02:32 +0000 Subject: [PATCH 133/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5027 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index df702f6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2b7a972..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2ae3891..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f2aadd739be176e3969bac49aa8a0bab78f5ae79 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 03:02:44 +0000 Subject: [PATCH 134/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 219 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 50 files changed, 4871 insertions(+), 5323 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1b7e949..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T01:27:38.599Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 681b7a1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..df702f6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f6ad23b..0284762 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-object-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2ae3891 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From 2029ff330d459fd9baf5396c9c63422a8435c722 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 01:53:36 +0000 Subject: [PATCH 135/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..9c6d806 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..e1addda 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..573112b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index d950d62..f6ad23b 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From b9e86d674c427b4957caac103e74c4379536d590 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 03:07:36 +0000 Subject: [PATCH 136/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5027 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index df702f6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2b7a972..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2ae3891..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bbfe66b10843a132aa79e86c5141c9d01d52ca18 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 03:07:50 +0000 Subject: [PATCH 137/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 219 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 51 files changed, 4871 insertions(+), 5428 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4ed8665..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T01:33:57.932Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 681b7a1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..df702f6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f6ad23b..0284762 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-object-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2ae3891 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -}); From da1431123c10882cc203750663ddc35b927702f9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Feb 2025 00:34:18 +0000 Subject: [PATCH 138/140] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 215ece5..9c6d806 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -57,7 +57,7 @@ function factory( path, options ) { isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 1 ) { diff --git a/lib/main.js b/lib/main.js index 8442b0e..e1addda 100644 --- a/lib/main.js +++ b/lib/main.js @@ -23,7 +23,7 @@ var isObjectLike = require( '@stdlib/assert-is-object-like' ); var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); var defaults = require( './defaults.js' ); var dset = require( './dset.js' ); @@ -97,7 +97,7 @@ function deepSet( obj, path, value, options ) { } isStr = isString( path ); if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + throw new TypeError( format( '1SV3A', path ) ); } opts = defaults(); if ( arguments.length > 3 ) { diff --git a/lib/validate.js b/lib/validate.js index 356d06a..573112b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var isString = require( '@stdlib/assert-is-string' ).isPrimitive; var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,18 +51,18 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1SV2V', options ) ); } if ( hasOwnProp( options, 'create' ) ) { opts.create = options.create; if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + return new TypeError( format( '1SV2o', 'create', opts.create ) ); } } if ( hasOwnProp( options, 'sep' ) ) { opts.sep = options.sep; if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); } } return null; diff --git a/package.json b/package.json index d950d62..f6ad23b 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-object-like": "^0.2.2", "@stdlib/assert-is-plain-object": "^0.2.2", "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From f34d322c5f2a45abc235754eaea62b160eba0fe1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Feb 2025 00:39:39 +0000 Subject: [PATCH 139/140] Remove files --- index.d.ts | 180 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5027 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4dda520..0000000 --- a/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index df702f6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2b7a972..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2ae3891..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4783d630d2c0a6d1216ee6f16065e07daa9407b7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Feb 2025 00:40:03 +0000 Subject: [PATCH 140/140] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 219 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 140 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 86 - docs/types/test.ts | 134 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/defaults.js | 39 - lib/dset.js | 80 - lib/factory.js | 99 - lib/index.js | 58 - lib/main.js | 120 - lib/validate.js | 74 - package.json | 62 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.dset.js | 292 -- test/test.factory.js | 221 - test/test.js | 201 - test/test.validate.js | 132 - 51 files changed, 4871 insertions(+), 5427 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/defaults.js delete mode 100644 lib/dset.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.dset.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 9368de2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-03T00:32:53.201Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ef04346..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f8db30d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2a813f7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '2 2 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -298,7 +295,7 @@ console.log( data ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -363,9 +360,9 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get +[@stdlib/utils/deep-get]: https://github.com/stdlib-js/utils-deep-get/tree/esm -[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck +[@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/utils-deep-pluck/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 681b7a1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b9b9ec0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set" -%% click B href "https://github.com/stdlib-js/utils-deep-set/tree/main" -%% click C href "https://github.com/stdlib-js/utils-deep-set/tree/production" -%% click D href "https://github.com/stdlib-js/utils-deep-set/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-deep-set/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-deep-set/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set -[production-url]: https://github.com/stdlib-js/utils-deep-set/tree/production -[deno-url]: https://github.com/stdlib-js/utils-deep-set/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-deep-set/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-deep-set/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-deep-set/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-deep-set/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-deep-set/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index be26546..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import deepSet from '../docs/types/index'; -export = deepSet; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c233480..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(Z,m){ -var k=require('@stdlib/assert-is-boolean/dist').isPrimitive,x=require('@stdlib/assert-is-string/dist').isPrimitive,P=require('@stdlib/assert-is-plain-object/dist'),p=require('@stdlib/assert-has-own-property/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist');function E(e,r){return P(r)?p(r,"create")&&(e.create=r.create,!k(e.create))?new TypeError(o('1SV2o',"create",e.create)):p(r,"sep")&&(e.sep=r.sep,!x(e.sep))?new TypeError(o('1SV2W',"sep",e.sep)):null:new TypeError(o('1SV2V',r));}m.exports=E -});var c=f(function(_,d){ -function T(){return{create:!1,sep:"."}}d.exports=T -});var q=f(function($,y){ -var h=require('@stdlib/assert-is-object-like/dist'),j=require('@stdlib/assert-has-own-property/dist'),L=require('@stdlib/assert-is-function/dist');function V(e,r,n,u){var a,s,i,t,v;for(s=r.length,a=!1,i=e,v=0;v3&&(t=R(i,u),t))throw t;return a?s=r.split(i.sep):s=r,C(e,s,i.create,n)}g.exports=D -});var O=f(function(er,w){ -var G=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-array/dist'),I=require('@stdlib/assert-is-object-like/dist'),J=require('@stdlib/error-tools-fmtprodmsg/dist'),M=l(),N=c(),Q=q();function U(e,r){var n,u,a,s;if(n=G(e),!n&&!H(e))throw new TypeError(J('1SV3A',e));if(a=N(),arguments.length>1&&(s=M(a,r),s))throw s;return n?u=e.split(a.sep):u=e,i;function i(t,v){return I(t)?Q(t,u,a.create,v):!1}}w.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=b(),X=O();W(S,"factory",X);module.exports=S; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 48ed974..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/validate.js", "../lib/defaults.js", "../lib/dset.js", "../lib/main.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepSet;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.js' );\nvar dset = require( './dset.js' );\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* var deepSet = require( '@stdlib/utils-deep-set' );\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAyB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAML,EAAUK,CAAQ,EAGnBJ,EAAYI,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACP,EAAWM,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHH,EAAYI,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG1G,KAdC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAehH,CAKAR,EAAO,QAAUM,ICzEjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAW,CACnB,MAAO,CACN,OAAU,GACV,IAAO,GACR,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAa,QAAS,iCAAkC,EACxDC,EAAa,QAAS,4BAA6B,EAevD,SAASC,EAASC,EAAKC,EAAOC,EAAQC,EAAM,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMJ,EAAM,OACZG,EAAO,GACPE,EAAIN,EACEQ,EAAI,EAAGA,EAAIH,IAChBE,EAAIN,EAAOO,CAAE,EACRZ,EAAcU,CAAE,GAFAE,IAEI,CACxB,GAAK,CAACX,EAAYS,EAAGC,CAAE,EACtB,GAAKL,EACJI,EAAGC,CAAE,EAAI,CAAC,MAEV,OAGGC,IAAMH,EAAI,GACTP,EAAYK,CAAI,EACpBG,EAAGC,CAAE,EAAIJ,EAAKG,EAAGC,CAAE,CAAE,EAErBD,EAAGC,CAAE,EAAIJ,EAEVC,EAAO,IAEPE,EAAIA,EAAGC,CAAE,CAEX,CAID,OAAOH,CACR,CAKAT,EAAO,QAAUI,IC/EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAe,QAAS,+BAAgC,EACxDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IA6DX,SAASC,EAASC,EAAKC,EAAMC,EAAOC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAO,GAGR,GADAI,EAAQX,EAAUQ,CAAK,EAClB,CAACG,GAAS,CAACV,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWN,EAAQ,2EAA4EM,CAAK,CAAE,EAGjH,GADAK,EAAOT,EAAS,EACX,UAAU,OAAS,IACvBU,EAAMX,EAAUU,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQJ,EAAK,MAAOK,EAAK,GAAI,EAE7BD,EAAQJ,EAEFH,EAAME,EAAKK,EAAOC,EAAK,OAAQJ,CAAM,CAC7C,CAKAX,EAAO,QAAUQ,ICvHjB,IAAAS,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,+BAAgC,EACxDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAO,IAuBX,SAASC,EAASC,EAAMC,EAAU,CACjC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQV,EAAUQ,CAAK,EAClB,CAACE,GAAS,CAACT,EAASO,CAAK,EAC7B,MAAM,IAAI,UAAWL,EAAQ,2EAA4EK,CAAK,CAAE,EAGjH,GADAI,EAAOP,EAAS,EACX,UAAU,OAAS,IACvBQ,EAAMT,EAAUQ,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAKH,EACJC,EAAQH,EAAK,MAAOI,EAAK,GAAI,EAE7BD,EAAQH,EAEFM,EAcP,SAASA,EAASC,EAAKC,EAAQ,CAC9B,OAAKd,EAAca,CAAI,EACfT,EAAMS,EAAKJ,EAAOC,EAAK,OAAQI,CAAM,EAEtC,EACR,CACD,CAKAjB,EAAO,QAAUQ,ICrDjB,IAAIU,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isBoolean", "isString", "isObject", "hasOwnProp", "format", "validate", "opts", "options", "require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_dset", "__commonJSMin", "exports", "module", "isObjectLike", "hasOwnProp", "isFunction", "deepSet", "obj", "props", "create", "val", "bool", "len", "v", "p", "i", "require_main", "__commonJSMin", "exports", "module", "isObjectLike", "isString", "isArray", "format", "validate", "defaults", "dset", "deepSet", "obj", "path", "value", "options", "isStr", "props", "opts", "err", "require_factory", "__commonJSMin", "exports", "module", "isString", "isArray", "isObjectLike", "format", "validate", "defaults", "dset", "factory", "path", "options", "isStr", "props", "opts", "err", "deepSet", "obj", "value", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8f6adcb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ed1c84f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 179a731..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random-base-randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..34596c2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object-like@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e,r){return o(r)?p(r,"create")&&(e.create=r.create,!n(e.create))?new TypeError(i("1SV2o","create",e.create)):p(r,"sep")&&(e.sep=r.sep,!t(e.sep))?new TypeError(i("1SV2W","sep",e.sep)):null:new TypeError(i("1SV2V",r))}function l(e,t,s,i){var n,o,m,l,a;for(o=t.length,n=!1,m=e,a=0;a3&&(j=m(a,p)))throw j;return l(e,d?n.split(a.sep):n,a.create,o)}function j(e,n){var o,p,d,a;if(!(o=t(e))&&!s(e))throw new TypeError(i("1SV3A",e));if(d={create:!1,sep:"."},arguments.length>1&&(a=m(d,n)))throw a;return p=o?e.split(d.sep):e,function(e,t){if(r(e))return l(e,p,d.create,t);return!1}}e(a,"factory",j);export{a as default,j as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2b7a972 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/dset.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for function options\n* @param {Options} options - function options\n* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep] - key path separator\n* @returns {(Error|null)} error or null\n*\n* @example\n* var opts = {};\n* var options = {\n* 'sep': '/'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1SV2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'create' ) ) {\n\t\topts.create = options.create;\n\t\tif ( !isBoolean( opts.create ) ) {\n\t\t\treturn new TypeError( format( '1SV2o', 'create', opts.create ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1SV2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isFunction from '@stdlib/assert-is-function';\n\n\n// MAIN //\n\n/**\n* Sets a nested property.\n*\n* @private\n* @param {ObjectLike} obj - input object\n* @param {Array} props - list of properties defining a key path\n* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist\n* @param {*} val - value to set\n* @returns {boolean} boolean indicating if the property was successfully set\n*/\nfunction deepSet( obj, props, create, val ) {\n\tvar bool;\n\tvar len;\n\tvar v;\n\tvar p;\n\tvar i;\n\n\tlen = props.length;\n\tbool = false;\n\tv = obj;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tp = props[ i ];\n\t\tif ( isObjectLike( v ) ) {\n\t\t\tif ( !hasOwnProp( v, p ) ) {\n\t\t\t\tif ( create ) {\n\t\t\t\t\tv[ p ] = {};\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( i === len-1 ) {\n\t\t\t\tif ( isFunction( val ) ) {\n\t\t\t\t\tv[ p ] = val( v[ p ] );\n\t\t\t\t} else {\n\t\t\t\t\tv[ p ] = val;\n\t\t\t\t}\n\t\t\t\tbool = true;\n\t\t\t} else {\n\t\t\t\tv = v[ p ];\n\t\t\t}\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Sets a nested property value.\n*\n* @param {ObjectLike} obj - input object\n* @param {(string|Array)} path - key path\n* @param {*} value - value to set\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} second argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {boolean} boolean indicating if the property was successfully set\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'woot' );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( null, 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* bool = deepSet( 'bap', 'a.beep.c', 'boop' );\n* // returns false\n*\n* @example\n* var arr = [\n* { 'a': [ {'x': 5} ] },\n* { 'a': [ {'x': 10} ] }\n* ];\n* var bool = deepSet( arr, '1.a.0.x', 25 );\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a/b/c', 'beep', {\n* 'sep': '/'\n* });\n* // returns true\n*\n* @example\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.e.c', 'boop', {\n* 'create': true\n* });\n* // returns true\n*/\nfunction deepSet( obj, path, value, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\tif ( !isObjectLike( obj ) ) {\n\t\treturn false;\n\t}\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn dset( obj, props, opts.create, value );\n}\n\n\n// EXPORTS //\n\nexport default deepSet;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*/\nfunction defaults() {\n\treturn {\n\t\t'create': false,\n\t\t'sep': '.'\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isArray from '@stdlib/assert-is-array';\nimport isObjectLike from '@stdlib/assert-is-object-like';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport validate from './validate.js';\nimport defaults from './defaults.js';\nimport dset from './dset.js';\n\n\n// MAIN //\n\n/**\n* Creates a reusable deep set function.\n*\n* @param {(string|Array)} path - key path\n* @param {Options} [options] - function options\n* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist\n* @param {string} [options.sep='.'] - key path separator\n* @throws {TypeError} first argument must be a string or key array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} deep set function\n*\n* @example\n* var dset = factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*/\nfunction factory( path, options ) {\n\tvar isStr;\n\tvar props;\n\tvar opts;\n\tvar err;\n\n\tisStr = isString( path );\n\tif ( !isStr && !isArray( path ) ) {\n\t\tthrow new TypeError( format( '1SV3A', path ) );\n\t}\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( isStr ) {\n\t\tprops = path.split( opts.sep );\n\t} else {\n\t\tprops = path;\n\t}\n\treturn deepSet;\n\n\t/**\n\t* Sets a nested property.\n\t*\n\t* @private\n\t* @param {ObjectLike} obj - input object\n\t* @param {*} value - value to set\n\t* @returns {boolean} boolean indicating if the property was successfully set\n\t*\n\t* @example\n\t* var obj = { 'a': { 'b': { 'c': 'd' } } };\n\t* var bool = dset( obj, 'beep' );\n\t*/\n\tfunction deepSet( obj, value ) {\n\t\tif ( isObjectLike( obj ) ) {\n\t\t\treturn dset( obj, props, opts.create, value );\n\t\t}\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Set a nested property value.\n*\n* @module @stdlib/utils-deep-set\n*\n* @example\n* import deepSet from '@stdlib/utils-deep-set';\n*\n* var obj = { 'a': { 'b': { 'c': 'd' } } };\n* var bool = deepSet( obj, 'a.b.c', 'beep' );\n* // returns true\n*\n* var dset = deepSet.factory( 'a/b/c', {\n* 'create': true,\n* 'sep': '/'\n* });\n*\n* obj = { 'a': { 'b': { 'c': 'd' } } };\n*\n* bool = dset( obj, 'beep' );\n* // returns true\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","create","isBoolean","TypeError","format","sep","isString","deepSet","obj","props","val","bool","len","v","p","i","length","isObjectLike","isFunction","path","value","isStr","err","isArray","arguments","dset","split","factory","setReadOnly","main"],"mappings":";;w4BAmDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,YACzBD,EAAKI,OAASH,EAAQG,QAChBC,EAAWL,EAAKI,SACd,IAAIE,UAAWC,EAAQ,QAAS,SAAUP,EAAKI,SAGnDD,EAAYF,EAAS,SACzBD,EAAKQ,IAAMP,EAAQO,KACbC,EAAUT,EAAKQ,MACb,IAAIF,UAAWC,EAAQ,QAAS,MAAOP,EAAKQ,MAG9C,KAdC,IAAIF,UAAWC,EAAQ,QAASN,GAezC,CC7BA,SAASS,EAASC,EAAKC,EAAOR,EAAQS,GACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAH,EAAMH,EAAMO,OACZL,GAAO,EACPE,EAAIL,EACEO,EAAI,EAAGA,EAAIH,IAChBE,EAAIL,EAAOM,GACNE,EAAcJ,IAFEE,IAAM,CAG1B,IAAMf,EAAYa,EAAGC,GAAM,CAC1B,IAAKb,EAGJ,MAFAY,EAAGC,GAAM,EAIV,CACIC,IAAMH,EAAI,GACTM,EAAYR,GAChBG,EAAGC,GAAMJ,EAAKG,EAAGC,IAEjBD,EAAGC,GAAMJ,EAEVC,GAAO,GAEPE,EAAIA,EAAGC,EAKT,CACD,OAAOH,CACR,CCeA,SAASJ,EAASC,EAAKW,EAAMC,EAAOtB,GACnC,IAAIuB,EAEAxB,EACAyB,EACJ,IAAML,EAAcT,GACnB,OAAO,EAGR,KADAa,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,ECxEO,CACNI,QAAU,EACVI,IAAO,KDuEHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAAOG,EAAMjB,EALRa,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAEgBtB,EAAKI,OAAQmB,EACvC,CE/DA,SAASO,EAASR,EAAMrB,GACvB,IAAIuB,EACAZ,EACAZ,EACAyB,EAGJ,KADAD,EAAQf,EAAUa,MACFI,EAASJ,GACxB,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAGvC,GADAtB,EDhCO,CACNI,QAAU,EACVI,IAAO,KC+BHmB,UAAUR,OAAS,IACvBM,EAAM1B,EAAUC,EAAMC,IAErB,MAAMwB,EAQR,OAJCb,EADIY,EACIF,EAAKO,MAAO7B,EAAKQ,KAEjBc,EAgBT,SAAkBX,EAAKY,GACtB,GAAKH,EAAcT,GAClB,OAAOiB,EAAMjB,EAAKC,EAAOZ,EAAKI,OAAQmB,GAEvC,OAAO,CACP,CACF,CCzCAQ,EAAAC,EAAA,UAAAF"} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index b8b7c5f..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/dset.js b/lib/dset.js deleted file mode 100644 index a189cd0..0000000 --- a/lib/dset.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 9c6d806..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index def7e87..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils-deep-set -* -* @example -* var deepSet = require( '@stdlib/utils-deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index e1addda..0000000 --- a/lib/main.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert-is-object-like' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( '1SV3A', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 573112b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '1SV2V', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( '1SV2o', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( '1SV2W', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f6ad23b..0284762 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Set a nested property value.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,41 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-object-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/boolean-ctor": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2ae3891 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.dset.js b/test/test.dset.js deleted file mode 100644 index 9a6421c..0000000 --- a/test/test.dset.js +++ /dev/null @@ -1,292 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.equal( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.equal( bool, true, 'returns true' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 613cb3e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.equal( typeof dset, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.equal( dset( values[ i ], 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, false, 'returns false' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.equal( bool, true, 'returns true' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cf05e84..0000000 --- a/test/test.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.equal( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns false' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.equal( bool, true, 'returns true' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.equal( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.equal( bool, true, 'returns true' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index f22e789..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), // eslint-disable-line no-new-wrappers - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.equal( obj.create, true, 'sets create option' ); - t.equal( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.equal( validate( obj, opts ), null, 'returns null' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -});